akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e6+9, M = (1<<31), OO = 0x3f3f3f3f;
LL a[N],b[N];
int main()
{
  int n;
  LL ans=0;
  scanf("%d",&n);
  for(int i=0;i<=n;++i) scanf("%lld",a+i);
  for(int i=0;i<n;++i)  scanf("%lld",b+i);
  for(int i=0;i<=n;++i)
  {
    LL v = min(a[i],b[i]);
    a[i]-=v;
    b[i]-=v;
    ans+=v;

    v = min(a[i+1],b[i]);
    a[i+1]-=v;
    b[i]-=v;
    ans+=v;

  }
  printf("%lld\n",ans);
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 5120
#include<iostream>
#include<stdio.h> 
#include<memory.h>
using namespace std;
string s,t;
int main()
{
	int i,j;
	char a[26],b[26];
	memset(b,'0',sizeof(b));
	memset(a,'0',sizeof(a));
	cin>>s>>t;
	for(i=s.length()-1;i>=0;i--)
	{
		if(s[i]==t[i])
		{
			b[s[i]-'a']=a[t[i]-'a']=s[i];
			continue;
		}
		else
		{
			if(b[s[i]-'a']=='0'&&a[t[i]-'a']=='0')
			{
				b[s[i]-'a']=t[i];
				a[t[i]-'a']=s[i];
				continue;				
			}
			else if(b[s[i]-'a']!='0')
			{
				if(b[s[i]-'a']==t[i])
				{
					continue;
				}
			}
			else if(a[t[i]-'a']!='0')
			{
				if(a[t[i]-'a']==s[i])
				{
					continue;
				}
			}
		}
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
int main() {
  int a, b,c;
  cin >> a >> b >> c;
  if((b*10+c)%4==0)cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  
  //要は今まで出てきた数字の中で最小であればよい。
  int count = 0;
  //組数を数える
  int L=N+1;
  //最小のものを取っておく
  int X;
  //一旦受け取るのに使う
  
  for(int i=0;i<N;i++){
    cin >> X;
    if(L > X){
      count++;
      L = X;
    } 
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

	int N;
	cin >> N;

	ll dp[N + 1];
	fill(dp, dp + N + 1, INF);
	rep(i, 0, 5) dp[i] = i;

	rep(i, 6, N + 1) {
		rep(j, 0, 5) {
			if(i - j >= 0) dp[i] = min(dp[i], dp[i - j] + j);
		}

		int j = 1;
		while(i - pow(6, j) >= 0) {
			int idx = i - pow(6, j);
			dp[i] = min(dp[idx] + 1, dp[i]);
			j++;
		}

		j = 1;
		while(i - pow(9, j) >= 0) {
			int idx = i - pow(9, j);
			dp[i] = min(dp[idx] + 1, dp[i]);
			j++;
		}
	}
	cout << dp[N] << endl;


}


Measured memory_bytes: 1024
#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
using namespace std;

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

	int h,w;
	cin >> h >> w;
	char c[100][100];
	rep(i,h){
		rep(j,w) cin >> c[i][j];
	}

	rep(i,h){
		rep(j,w) cout << c[i][j];
		cout << endl;
		rep(j,w) cout << c[i][j];
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++) 
#define rep(i, a) loop(i, 0, a)
using namespace std;
const int MOD = 1000000007;
const int inf = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
int main(){
    int n;  cin >> n;
    vvi A(n, vi(n));
    rep(i, n)rep(j, n)cin >> A[i][j];
    long long int ans = 0;
    vvi judge(n, vi(n));
    rep(k, n)rep(i, n)rep(j, n){
        if(A[i][j] > A[i][k] + A[k][j]){
            cout << -1 << endl;
            return 0;
        }
        if(A[i][j] == A[i][k] + A[k][j] && i != j && j != k && k != i)
            judge[i][j] = true;
    }
    rep(i, n){
        rep(j, n){
            if(!judge[i][j] && i > j){
                ans += A[i][j];
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, K, A[105];
bool visited[int(1e5+5)], ans[int(1e5+5)];

bool Solve(int num){
  if (visited[num]) return ans[num];
  visited[num] = true;

  for (int i = 0; i < N; i++){
    if (num - A[i] < 0) continue;
    if (!Solve(num-A[i])) return ans[num] = true;
  }
  return ans[num] = false;
}

int main(){
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> A[i];
  if (Solve(K)) cout << "First" << endl;
  else cout << "Second" << endl;

  return 0;
}


Measured memory_bytes: 8432
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,x,t;
  cin >> n >> x >> t;
  
  int c = 0;
  
  if(n % x != 0){
    c= (n / x + 1)*t;
  }else{
    c= (n / x)*t;
  }
  cout << c << endl;
  
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };



void solve() {
    ll a, b, c, d, e , m, n, k, x,l,r,t;
    string s;
    ll ans = 0;
    double dans = 0;
    string sans = "Yes";
    vector<ll> ar;

    cin >> n >> t;

    ll _min = INF;
    int flag = 0;

    rep(i,n){
        ll co, ti;
        cin >> co >> ti;
        
        if(t>=ti){
            _min = min(_min, co);
            flag = 1;
        }
    }

    if(flag==0){
        std::cout << "TLE" << endl; 
        return;
    }

    ans = _min;

    std::cout << ans << endl; 

    // std::cout << sans << endl; 
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

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

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N;
int K;
int h[100010];
int dp[100010];

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    cin>>N>>K;
    
    rep(i,0,100010)dp[i]=INF;
    dp[1]=0;
    rep(i,1,N+1)cin>>h[i];
    rep(i,2,N+1){
        rep(j,1,K+1){
            if(i-j<1)continue;
            chmin(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout<<dp[N]<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    return 0;
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	printf("%d\n", ( a < b ? a : b ) + ( c < d ? c : d ));
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		do{
			int x = i;
			if(x%3 == 0){
				System.out.printf(" %d", i);
				continue;
			}
			do{
				if(x%10 == 3){
					System.out.printf(" %d", i);
					break;
				}
				x /= 10;
			}while(x > 0);
		}while(++i <= n);
		System.out.printf("\n");
	}
}

Measured memory_bytes: 40196
#include<iostream>
#include<string>
using namespace std;
string s;
char ans[1005];
int w;
int main()
{
    std::ios::sync_with_stdio(false);
    cin >> s;
    cin >> w;
    int cnt = 0;
    for (int i = 0; i < s.size(); i += w)
    {
        ans[cnt++] = s[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <ctime>
#include <list>
using namespace std;
static const double EPS = 1e-8;
typedef long long ll;
typedef pair<int,int> PI;
#ifndef M_PI
const double M_PI=acos(-1);
#endif
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int((a).size()))
#define F first
#define S second
int dx[]={0,1,0,-1,0,0},dy[]={1,0,-1,0,0,0};
int dz[]={0,0,0,0,1,-1};

int st[10000];
int ed[10000];
int n;

void solve(){
  priority_queue<PI> q;
  rep(i,n){
    int hh,mm,ss;
    scanf("%d:%d:%d",&hh,&mm,&ss);
    st[i]=hh*3600+mm*60+ss;
    q.push(mp(-st[i],0));
    scanf("%d:%d:%d",&hh,&mm,&ss);
    ed[i]=hh*3600+mm*60+ss;
    q.push(mp(-ed[i],1));
  }
  int ans=0;
  int cu=0;
  while(!q.empty()){
    int cc=q.top().S;
    q.pop();
    cu+=cc;
    if(cc==0 && cu==0)++ans;
    else if(cc==0)--cu;
  }
  cout<<ans<<endl;
}


main(){
  while(cin>>n,n)
    solve();
}

Measured memory_bytes: 0
N=int(input())
L=[]
for i in range(N):
    a,b,c=map(int,input().split())
    L.append([a,b,c])

dp=[[0]*N for _ in range(3)]
dp[0][0]=L[0][0]
dp[1][0]=L[0][1]
dp[2][0]=L[0][2]

for j in range(1,N):
    dp[0][j]=max(dp[1][j-1],dp[2][j-1])+L[j][0]
    dp[1][j]=max(dp[0][j-1],dp[2][j-1])+L[j][1]
    dp[2][j]=max(dp[0][j-1],dp[1][j-1])+L[j][2]

print(max(dp[0][N-1],dp[1][N-1],dp[2][N-1]))

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

int main() {
	clock_t start = clock();
	int D;
	cin >> D;

	vector<int> c(26);
	vector<vector<int>> s(D, vector<int>(26));
	vector<int> t(D);
	vector<vector<int>> last(D, vector<int>(26, 0));
	vector<int> sat(D);
	vector<int> sat_tmp(26);

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

	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) {
			cin >> s[i][j];
		}
	}

	/*********************************/
	for (int i = 0; i < D; i++) {
		for (int k = 0; k < 26; k++) {
			for (int j = 0; j < 26; j++) {
				if (i == 0) {
					last[i][j] = 0;
				} else {
					last[i][j] = last[i - 1][j];
				}
			}
			last[i][k] = i + 1;
			if (i == 0) {
				sat_tmp[k] = s[i][k];
			} else {
				sat_tmp[k] = s[i][k] + sat_tmp[i - 1];
			}
			int satisfaction = 0;
			for (int j = 0; j < 26; j++) {
				satisfaction += c[j] * (i + 1 - last[i][j]);
			}
			sat_tmp[k] -= satisfaction;
		}
		vector<int>::iterator iter = max_element(sat_tmp.begin(), sat_tmp.end());
		size_t index = distance(sat_tmp.begin(), iter);
		t[i] = index;

		for (int j = 0; j < 26; j++) {
			if (i == 0) {
				last[i][j] = 0;
			} else {
				last[i][j] = last[i - 1][j];
			}
		}
		last[i][t[i]] = i + 1;
		if (i == 0) {
			sat[i] = s[i][t[i]];
		} else {
			sat[i] = s[i][t[i]] + sat[i - 1];
		}
		int satisfaction = 0;
		for (int j = 0; j < 26; j++) {
			satisfaction += c[j] * (i + 1 - last[i][j]);
		}
		sat[i] -= satisfaction;
	}

	// for (int i = 0; i < D; i++) {
	// 	cout << sat[i] << endl;
	// }
	int max_sat = sat[D - 1];
	/*********************************/
	vector<int> t_new(D);
	std::srand(time(NULL));

	while (clock() - start < 1800000) {
		t_new = t;
		t_new[rand() % D] = rand() % 26;

		for (int i = 0; i < D; i++) {
			for (int j = 0; j < 26; j++) {
				if (i == 0) {
					last[i][j] = 0;
				} else {
					last[i][j] = last[i - 1][j];
				}
			}
			last[i][t_new[i]] = i + 1;
			if (i == 0) {
				sat[i] = s[i][t_new[i]];
			} else {
				sat[i] = s[i][t_new[i]] + sat[i - 1];
			}
			int satisfaction = 0;
			for (int j = 0; j < 26; j++) {
				satisfaction += c[j] * (i + 1 - last[i][j]);
			}
			sat[i] -= satisfaction;
		}
		if (sat[D - 1] > max_sat) {
			// cout << sat[D - 1] << endl;
			max_sat = sat[D - 1];
			t = t_new;
		}
	}

	/*********************************/

	for (int i = 0; i < D; i++) {
		cout << t[i] + 1 << endl;
	}
	// cout << sat[D - 1] << endl;
	// cout << clock() - start << endl;

	return 0;
}

Measured memory_bytes: 3748
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {
    public static int[] dp;
    public static ArrayList<Integer>[] graph;
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] lo = reader.readLine().split(" ");
        int N =Integer.parseInt(lo[0]);
        int M =Integer.parseInt(lo[1]);
        graph = new ArrayList[N+1];
        dp = new int[N+1];
        for (int i = 0; i <=N ; i++) {
            dp[i]=-1;
            graph[i]=new ArrayList<>();
        }
        for (int i = 0; i <M ; i++) {
            String[] xy = reader.readLine().split(" ");
            int x = Integer.parseInt(xy[0]);
            int y = Integer.parseInt(xy[1]);
            graph[x].add(y);
        }
        int res =0;
        for (int i = 1; i <=N ; i++) {
            res=Math.max(res,dfs(i));
        }
        System.out.println(res);
    }
    public static int dfs(int a){
        if(dp[a]!=-1) return dp[a];
        int temp = 0;
        for(int y:graph[a]){
            temp = Math.max(temp,1+dfs(y));
        }
        dp[a] = temp;
        return temp;
    }
}


Measured memory_bytes: 59152
L,X=map(int,input().split())
b=[1];p=[1]
for i in range(L):
	b.append(b[-1]*2 + 3)
	p.append(p[-1]*2 + 1)
def f(L, X):
	if L==0 or X<0:
		return 0 + (X>0)
	elif X <= 1 + b[L-1]:
		return f(L-1, X-1)
	else:
		return p[L-1] + 1 + f(L-1, X-b[L-1]-2)
print(f(L, X))

Measured memory_bytes: 3064
from collections import defaultdict

N,C = map(int, input().split())
D = [tuple(map(int, input().split())) for _ in range(C)]
change = dict()
for i in range(C):
    for j in range(C):
        change[(i+1,j+1)] = D[i][j]

grid = [tuple(map(int, input().split())) for _ in range(N)]

mod_0 = defaultdict(int)
mod_1 = defaultdict(int)
mod_2 = defaultdict(int)

for i in range(N):
    for j in range(N):
        if (i+1 + j + 1) % 3 == 0:
            mod_0[grid[i][j]] += 1
        elif (i+1 + j + 1) % 3 == 1:
            mod_1[grid[i][j]] += 1
        elif (i+1 + j + 1) % 3 == 2:
            mod_2[grid[i][j]] += 1

ans = float("inf")
# 色のとり方
# 余り0がi,1がj,2がkになる
for i in range(C):
    
    for j in range(C):
        if i == j:
            continue
        for k in range(C):
            tmp = 0
            if i == k or j == k:
                continue
            
            for c,v in mod_0.items():
               tmp += change[(c, i+1)] * v
            for c,v in mod_1.items():
                   tmp += change[(c, j+1)] * v
            for c,v in mod_2.items():
                   tmp += change[(c, k+1)] * v

            ans = min(ans, tmp)
            
print(ans)

Measured memory_bytes: 49756
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
signed main() {
	string s; cin >> s;
	int t = 0;
	while (t + 1 < s.size()) {
		if (s[t] == 'h'&&s[t + 1] == 'i')t += 2;
      else break;
	}
	cout << (t == s.size() ? "Yes" : "No") << endl;;
}

Measured memory_bytes: 256
H,W,D=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(H)]
Q=int(input())
X=[[0,0] for _ in range(H*W+1)]
for i in range(H):
    for j in range(W):
        X[A[i][j]][0]=i
        X[A[i][j]][1]=j
M=[0]*(H*W+1)
for d in range(D+1,H*W+1):
        M[d]=abs(X[d][0]-X[d-D][0])+abs(X[d][1]-X[d-D][1])+M[d-D]

for i in range(Q):
    L,R=map(int,input().split())
    print(M[R]-M[L])

Measured memory_bytes: 20712
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    int sum = 0;
    int max = 0;
    std::cin >> N;
    int A[2][N+1];
    for (int i = 0;i < N;i++) {
        cin >> A[0][i];
    }for(int i = 0;i < N;i++){
        cin >> A[1][i];
    } 
    
    // for (int i = 0;i < N;i++) {
    //     cout << A[0][i];
    // }for(int i = 0;i < N;i++){
    //     cout << A[1][i];
    // } 
    
    for(int count = 0;count < N;count++){
        for (int k = 0; k < N; k++) {
            //std::cout << " k:"<< k << std::endl;
            //std::cout << " count:"<< count << std::endl;
            if(count > k){
                sum = sum + A[0][k];
                //cout << A[0][k];
            }else if(count == k){
                sum = sum + A[0][k]+ A[1][k];
                //cout << A[0][k] << A[1][k];
            }else if(count < k){
                sum = sum + A[1][k];
                //cout << A[1][k];
            }else{}
        }
        //std::cout <<"sum" <<sum << std::endl;
        if(max < sum){
            max = sum;
        }
    sum = 0;
    }
    std::cout << max << std::endl;
}


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

int main() {
  int w;
  while (cin >> w, w != -1) {
    int c = 1150;
    if (w > 30) {
      c += (w - 30) * 160 + 2650;
    } else if (w > 20) {
      c += (w - 20) * 140 + 1250;
    } else if (w > 10) {
      c += (w - 10) * 125;
    }
    cout << 4280 - c << "\n";
  }
}


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

 int main() {
     string s, t;
     int a, b;
     string u;
     cin >> s >> t;
     cin >> a >> b;
     cin >> u;

     if(s == u) a--;
     else b--;

     cout << a << " " << b << endl;
 }

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


int main(void)
{
	int n, m;

	while(scanf("%d%d", &n, &m)==2)
	{
		vi h(n+1);
		for(int i=1;i<=n;i++) scanf("%d", &h[i]);

		vvi e(n+1);
		for(int i=0;i<m;i++)
		{
			int a, b;
			scanf("%d%d", &a, &b);

			e[a].push_back(b);
			e[b].push_back(a);
		}

		int ans=0;
		for(int i=1;i<=n;i++)
		{
			bool is_good=true;
			for(int me:e[i])
			{
//				printf("compare i=%d %d\n", i, me);
				if(h[i]<=h[me]) is_good=false;
			}
			if(is_good)
			{
//				printf("%d is good\n", i);
				ans++;
			}
		}
//		for(int mh:h) printf("%d ", mh); printf("\n");
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 8272
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    n = int(input())
    p = list(map(int, input().split()))

    count = 0
    for i in range(1, n-1):
        if max(p[i-1:i+2]) > p[i] and min(p[i-1:i+2]) < p[i]:
            # print(i)
            count += 1

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 6868
def get_no_days(day_str):
    day_split = day_str.split(' ')
    year = int(day_split[0])
    month = int(day_split[1])
    day = int(day_split[2])
    result = 0

    for y in range(1, year, 1):
        if y % 3 != 0:
            result += 195
        else:
            result += 200
    year_not_mod_3 = (year % 3 != 0)
    for m in range(1, month, 1):
        if year_not_mod_3 and m % 2 == 0:
            result += 19
        else:
            result += 20
    result += day
    return 196471 - result

total = int(input())
for i in range(total):
    d = input()
    print(str(get_no_days(d)))





Measured memory_bytes: 5596
#include<iostream>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long double ld;
const long double pi= 3.14159265358979323846264338327950288;
#define int long long
signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	for (int i = 0; i < 10000000; i++) {
		int d = a / 2, e = b / 2, f = c / 2;
		if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
			cout << i << endl;
			return 0;
		}
		a = e + f;
		b = d + f;
		c = d + e;
	}
	cout << -1 << endl;
}

Measured memory_bytes: 256
h,w,k=map(int,input().split())
c=[]
#行ごと
hk=[]
for i in range(h):
    kki=0
    hwi=input()
    hw=[]
    for j in range(w):
        if hwi[j]=='#':
            hw.append(1)
            kki+=1
        else:
            hw.append(0)
    c.append(hw)
    hk.append(kki)
kk=sum(hk)
ans=0
#残す行を選ぶ
for i in range(2**h):
    #列ごと
    wk=[0]
    wk*=w
    for j in range(h):
        if (i>>j &1):
            #残った行の列ごとの和
            for l in range(w):
                wk[l]+=c[j][l]
    #残す列を選ぶ
    for j in range(2**w):
        ansi=0
        for l in range(w):
            if (j>>l & 1):
                ansi+=wk[l]
        if ansi==k:
            ans+=1
    
print(ans)

Measured memory_bytes: 9188
#include<iostream>
#include <string>
#include <cstdlib> //絶対値利用のため
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
	ll k, a, b;
	cin >> k >> a >> b;
	if (a + 2 >= b) {
		cout << 1 + k << endl;
	}
	else if (k < a + 1){
		cout << 1 + k << endl;
	} else {
		ll sum = a;
		sum += (b - a)*((k - a + 1) / 2) + (k - a + 1) % 2;
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <deque>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdlib>
#include <cassert>

#define el_cucuy ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long
#define pb push_back
#define bpc __builtin_popcount
#define pii pair <int, int>
#define f first
#define s second

const llong mxn = 4 * 1e5 + 3;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

llong q, n, m, a[mxn], dp[mxn], k;

int main(){
    ///freopen("input.txt", "r", stdin);
    ///freopen("output.txt", "w", stdout);
    cin >> n >> k;
    for (int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    dp[2] = abs(a[1] - a[2]);
    for (int i = 3; i <= n; i ++){
        dp[i] = inf;
        for (int j = 1; j <= min(i - 1, (int)k); j ++){
            dp[i] = min(abs(a[i] - a[i - j]) + dp[i - j], dp[i]);
        }
    }cout << dp[n];
    return 0;
}


Measured memory_bytes: 3072
h,w=map(int,input().split())
s=[input()for _ in range(h)]
for i in range(1,h-1):
  for j in range(1,w-1):
    if s[i][j]=="#":
      if s[i-1][j]+s[i+1][j]+s[i][j-1]+s[i][j+1]=="....":print("No");exit()
print("Yes")

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

int main() {
  int X, N;
  cin >> X >> N;
  int a[102], P, ans = 0;
  fill(a, a+102, 0);
  for (int i=0; i<N; i++) {
    cin >> P;
    a[P]++;
  }
  for (int i=0; i<=101; i++) {
    if (a[i])
      continue;
    if (abs(X-i) < abs(X-ans))
      ans = i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int X,N; cin >> X >> N;
  v<int> p(N);
  rep(i,N){
    cin >> p[i];
  }
  //priority_queue<int,v<int>,greater<int>> pq;
  int ans=0;
  for(int i=0;i<=101;i++){
    int cnt=0;
    rep(j,N){
      if(i!=p[j]) cnt++;
    }
    if(cnt==N){
      int tmp=i;
      if(abs(X-tmp)<abs(X-ans)){
        ans=tmp;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3664
//kid_kb//

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ull unsigned long long int
#define lower(str) transform(str.begin(),str.end(),str.begin(),::tolower);
#define upper(str) transform(str.begin(),str.end(),str.begin(),::toupper);
#define mod 1000000007
#define SORT(vec) sort(vec.begin(),vec.end());
#define pb push_back
#define csb __builtin_popcount
#define msb(n) (ll)(log2(n))
#define DIG(n) floor(log10(n))+1
#define kb ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ptr(arr) for(auto i:arr)cout<<i<<" ";
#define ptr2(vec) for(auto i:vec){for(auto j: i){cout<<j<<" ";}cout<<endl;}
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mem(a,val) memset(a,val,sizeof(a))
//cout<<fixed<<setprecision(8)<<endl;
 
int main()
{
    kb
    //                                            Let's Fight !!!!!!!
    ll t;
    t=1;
    // cin>>t;
    while(t--){
       string n;
       cin>>n;
       ll sum=0;
       rep(i,0,n.length()){
           sum+=n[i]-'0';
           if(sum>=9)sum-=9;
       }
       if(sum%9==0)cout<<"Yes"<<endl;
       else cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 3740
N = int(input())
info = [[] for _ in range(N)]
people = [-1] * N
for i in range(N):
    A = int(input())
    if A == 0:
        info[i].append([0])
    for j in range(A):
        x , y = map(int,input().split())
        info[i].append([A , x - 1 , y])
#print(info[0][0][0])
ans = 0
# ビット全探索を行う
for i in range(2 ** N):
    cnt = 0
    Flag = True
    # ビットが１の時、正直者としてpeopleに格納
    for j in range(N):
        if i >> j & 1:
            cnt += 1
            people[j] = 1
        else:
            people[j] = 0
    for j in range(N):
        # 正直者の発言と実際に正直者であるかを判定
        if i >> j & 1:
            info_num = info[j][0][0]
            for k in range(info_num):
                judge = info[j][k][2]
                origin = people[info[j][k][1]]
                if judge != origin:
                    Flag = False
                    break
        if not Flag:
            break
    if Flag:
        if ans < cnt:
            ans = cnt
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(1){
        c -= b;
        if(c<=0){
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
}

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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846

    vector<pair<int,int>>dist(10);

    double distance(int i , int j){
         int d=(dist[i].first - dist[j].first)*(dist[i].first - dist[j].first) + (dist[i].second - dist[j].second)*(dist[i].second - dist[j].second);
         double ans=sqrt(double(d));
         return ans;
    }

    void solve(){
        int n;
        cin>>n;
        for(int i=0;i<n;i++)
            cin>>dist[i].first>>dist[i].second;
        vector<int>path(n);
        for(int i=0;i<n;i++)
            path[i]=i;
        double total_len=0;
        double total_count=1;
        for(int i=1;i<n;i++)
            total_len+=distance(path[i],path[i-1]);
        while(next_permutation(path.begin(),path.end())){
            total_count++;
            double dist=0;
            for(int i=1;i<n;i++)
                dist+=distance(path[i],path[i-1]);
//            cout<<"in "<<dist<<"\n";
            total_len+=dist;
        }
//        cout<<total_count<<"\n";
        double ans=total_len/((double)total_count);
        cout<<ans;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 3804
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0511

#include <algorithm>
#include <iostream>
#include <vector>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

//テ」ツδ榲」ツつッテ」ツδュテ・ツョツ堙ァツセツゥ
#define ALL(v) (v).begin(),(v).end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); ++i)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define SORT(x) sort(begin(x),end(x))
#define SELECT_SORT(x, n) sort(begin(x),begin(x)+n)
#define SWAP(type, a, b) do {type tmp = a; a = b; b = tmp;} while (0)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))

//テ・ツョツ堙ヲツ閉ー
#define INF 2000000000000
#define MAX 10

//DEBUGテァツ板ィ
#define BAR() cout << "----------------------------" << endl;
#define DUMP(v) (cerr << #v << ": " << v << endl)
#define PRINT(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;


int main()
{
	string words;
	
	cin >> words;
	
	rep(i,words.length()){
		char tmp;
		if(words[i]=='A'){
			cout << 'X';
		}else if(words[i]=='B'){
			cout << 'Y';
		}else if(words[i]=='C'){
			cout << 'Z';
		}else{
			tmp = words[i]-3;
			cout << tmp;
		}
	}
	cout << endl;
	
}

Measured memory_bytes: 1180
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
//#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 3000000;
int mod = 1e9 + 7;
int f[N], invf[N];
int binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1) % mod;
    int z = binpow(x, y / 2);
    return z * z % mod;
}
int cnk(int n, int k){
    return f[n] * invf[n - k] % mod * invf[k] % mod;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    a = a * binpow(100, mod - 2) % mod;
    b = b * binpow(100, mod - 2) % mod;
    c = c * binpow(100, mod - 2) % mod;
    a = a * binpow((1 - c + mod) % mod, mod - 2) % mod;
    b = b * binpow((1 - c + mod) % mod, mod - 2) % mod;
    int d = binpow((1 - c + mod) % mod, mod - 2);
    f[0] = 1;
    for (int i = 1; i <= n + n; i++) f[i] = f[i - 1] * i % mod;
    for (int i = 0; i <= n + n; i++) invf[i] = binpow(f[i], mod - 2);
    int ans = 0;
    for (int i = n; i <= n + n - 1; i++){
        int x = binpow(a, n) % mod * binpow(b, i - n) % mod * cnk(i - 1, n - 1) % mod;
        int y = binpow(b, n) % mod * binpow(a, i - n) % mod * cnk(i - 1, n - 1) % mod;
        ans = (ans + (x + y) * i) % mod;
    }
    cout << ans * d % mod;
}


Measured memory_bytes: 6016
#include <stdio.h>

int
main(int argc, char argv[])
{
  int N, M, X, Y;
  int x[100], y[100];
  scanf("%d%d%d%d", &N, &M, &X, &Y);
  for(int i = 0; i < N; i++){
    scanf("%d", &x[i]);
  }
  for(int i = 0; i < M; i++){
    scanf("%d", &y[i]);
  }
  
  int x_max = -100; int y_min = 100;
  for(int i = 0; i < N; i++){
    if(x_max < x[i]){
      x_max = x[i];
    }
  }
  for(int i = 0; i < M; i++){
    if(y_min > y[i]){
      y_min = y[i];
    }
  }
  
  for(int i = X + 1; i <= Y; i++){
    if(x_max < i && i <= y_min){
      printf("%s\n", "No War");
      break;
    }
    else if(i == Y){
      printf("%s\n", "War");
    }
  }
  
  return 0;
}


Measured memory_bytes: 128
a,b = input().split(' ')
a = int(a)
b = int(b)
 
ans = 100000000000
 
for i in range(a, min(b, a + 2019)):
    for j in range(i + 1, min(b + 1, a + 2019)):
        if (i * j) % 2019 < ans:
            ans = (i * j) % 2019
 
print(ans)

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

using namespace std;

int nr, N, a[100009], b[100009], A[100009], B[100009], id[100009], sz[100009], may[100009], both1[100009];
const int INF = 1e8;

bool cmp (int i, int j)
{
    if (A[i] + B[i] == A[j] + B[j]) return (A[i] < A[j]);
    return (A[i] + B[i] < A[j] + B[j]);
}

int findPair (int x, int y)
{
    int p = 1, u = nr, mij;
    while (p <= u)
    {
        mij = (p + u) >> 1;
        if (a[mij] == x && b[mij] == y) return mij;
        if (a[mij] + b[mij] < x + y || (a[mij] + b[mij] == x + y && a[mij] < x)) p = mij + 1;
        else u = mij - 1;
    }
    return 0;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d %d", &A[i], &B[i]), id[i] = i;
sort (id + 1, id + N + 1, cmp);
if (A[2] != B[1] || A[id[1]] + B[id[1]] < A[2] || A[1] != 0 || B[2] != 0)
{
    printf ("-1\n");
    return 0;
}
for (int i=1; i<=N; i++)
    if ((A[i] == 0 && i != 1) || (B[i] == 0 && i != 2))
    {
        printf ("-1\n");
        return 0;
    }
for (int i=1; i<=N; i++)
{
    int j = i;
    while (j + 1 <= N && A[id[j]] == A[id[j + 1]] && B[id[j]] == B[id[j + 1]])
        j ++;
    a[++nr] = A[id[i]], b[nr] = B[id[i]], sz[nr] = j - i + 1;
    i = j;
}
for (int i=1; i<=nr; i++)
    may[i] = (findPair (a[i] + 1, b[i] - 1) != 0),
    both1[i] = (findPair (a[i] - 1, b[i] - 1) != 0);
if (!may[1])
{
    printf ("-1\n");
    return 0;
}
for (int i=1; i<=nr; i++)
    if ((a[i] > 0 && findPair (a[i] - 1, b[i]) == 0 && findPair (a[i] - 1, b[i] + 1) == 0 && both1[i] == 0) ||
        (b[i] > 0 && findPair (a[i], b[i] - 1) == 0 && findPair (a[i] + 1, b[i] - 1) == 0 && both1[i] == 0))
        {
            printf ("-1\n");
            return 0;
        }
int ans = 0;
for (int i=1; i<=nr; i++)
{
    int j = i;
    while (j < nr && a[j] + b[j] == a[j + 1] + b[j + 1])
        j ++;
    ///
    if (i == 1)
    {
        for (int k=1; k<j; k++)
            ans += max (sz[k], sz[k + 1]);
    }
    else
    {
        int cm = 0;
        for (int k=i; k<=j; k++)
        {
            if (both1[k])
            {
                ans += sz[k];
                if (may[k]) cm = min (cm, sz[k]);
                else cm = 0;
                continue;
            }
            if (sz[k] > cm) ans += sz[k] - cm;
            ans += sz[k];
            if (may[k]) cm = sz[k];
            else cm = 0;
        }
    }
    ///
    i = j;
}
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 3328
x, n = [int(v) for v in input().split()]
ps = {int(v) for v in input().split()}

upper = x
for i in range(n + 1):
    if x + i not in ps:
        upper = x + i
        break

lower = x
for i in range(n + 1):
    if x - i not in ps:
        lower = x - i
        break

if upper - x < x - lower:
    print(upper)
else:
    print(lower)


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

int main() {
	string S;  cin >> S;
	int w;  cin >> w;
	
	string ans = "";
	for (int i = 0; i < S.length(); i++) {
		if (i%w == 0) ans += S.substr(i, 1);
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
//created by pyoxiao on 2020/05/10
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
int n, m, x;
int tmp[20];
struct node{
    int c, v[20];
}a[20];
void solve() {
    scanf("%d %d %d", &n, &m, &x);
    for(int i = 1; i <= n; i ++) {
        scanf("%d", &a[i].c);
        for(int j = 1; j <= m; j ++) {
            scanf("%d", &a[i].v[j]);
        }
    }
    int ans = 1e9;
    for(int mask = 0; mask < 1 << n; mask ++) {
        for(int i = 1; i <= m; i ++) tmp[i] = 0;
        int cur = 0;
        for(int i = 0; i < n; i ++) {
            if((mask >> i) & 1) {
                cur += a[i + 1].c;
                for(int j = 1; j <= m; j ++) {
                    tmp[j] += a[i + 1].v[j];
                }
            }
        }
        bool ok = 1;
        for(int i = 1; i <= m; i ++) {
            if(tmp[i] >= x) continue;
            ok = 0; break;
        }
        if(ok) {
            ans = min(ans, cur);
        }
    }
    if(ans == 1e9) puts("-1");
    else printf("%d\n", ans);
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e5+5;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    char a[2][3];
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < 3; j++)
            cin >> a[i][j];
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < 3; j++)
        {
            if (a[i][j] != a[1-i][2-j])
                return cout << "NO", 0;
        }
    cout << "YES";
    return 0;
}

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

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    int P = C/B;
    int S = A/D ;

    if(C%B != 0) P++;
    if(A%D != 0) S++;

    if(P <= S) cout << "Yes" << endl;
    else if(P > S) cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3588
n = int(input())
list_A = list(map(int, input().split()))
set_a = list(set(list_A))
dic_A = dict()

for i in range(len(set_a)):
    j = str(set_a[i])
    dic_A[j] = 0

for i in list_A:
    j = str(i)
    dic_A[j] += 1
ans = 0
for s, i in dic_A.items():
    c = int(s)
    if i >= c:
        ans += i - c
    else:
        ans += i

print(ans)

Measured memory_bytes: 26356
import math
from collections import defaultdict

def get_max_frequency(x):
  n = 1
  while True:
    if n*(n+1)/2 <= x and x < (n+1)*(n+2)/2:
      break
    n += 1
  return n

N = int(input())
divided = N
d = defaultdict(int)
ans = 0

for i in range(2, int(math.sqrt(N)//1)+1):
  while True:
    if divided%i == 0:
      divided //= i
      d[i] += 1
    else:
      break
d[divided] += 1
if 1 in d:
  del d[1]

for v in d.values():
  ans += get_max_frequency(v)

print(ans)

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

int main()
{
    int N, x,y,i,j,count=0;
    scanf("%d", &N);
    x=N/2;
    y=N%2;

    char str[N];

    scanf("%s", str);

    if(y!=0)
    {
        printf("No\n");
    }

    else
    {
        for(i=0; i < x; i++)
        {
            if(str[i]==str[i+x])
                count++;
        }

        if(count == x)
            printf("Yes\n");

        else
            printf("No\n");
    }


    return 0;
}


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

typedef long long ll;

ll cur = 9;

bool Get(ll x)
{
	if (x == 0) return false;
	cout << "? " << x << endl; fflush(stdout);
	char ch; scanf(" %c", &ch);
	return ch == 'Y';
}

void Answer(ll cur)
{
	cout << "! " << cur << endl; fflush(stdout);
}

int main()
{
	ll bot = 1;
	int cnt = 0;
	while (Get(bot) && cnt <= 10) { cnt++; bot *= 10ll; }
	if (cnt > 10) {
		ll cur = 9;
		ll res = 1;
		while (!Get(cur)) { res *= 10ll; cur = 10ll * cur + 9ll; }
		Answer(res); return 0;
	}
	ll pw = 100000000000ll;
	ll add = 99999999999ll;
	ll res = 0;
	for (int i = 0; i < cnt; i++) {
		int lef = i == 0? 1: 0, rig = 9;
		while (lef <= rig) {
			int mid = lef + rig >> 1;
			if (Get((10ll * res + mid) * pw + add)) rig = mid - 1;
			else lef = mid + 1;
		}
		res = 10ll * res + (rig + 1); pw /= 10ll; add /= 10ll;
	}
	Answer(res);
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int count =  1;
  int ans = 0;
  while (count < b) {
    count--;
    count += a;
    ans++;
  }
  cout << ans << endl;
}

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

int main() {
    
    ll A, B, C, K, sum = 0;
    
    cin >> A >> B >> C >> K;
    
    if(K < A){
        sum += K;
    }
    
    if(K >= A){
        sum += A;
    }
    
    if(A+B < K && K <= A+B+C){
        sum += -(K-(A+B));
    }
    
    cout << sum;
    
    return 0;
    
}

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

int main() {
  int a;
  int b;
  int c;	
  int d;
  int e;	//左の皿
  int f;	//右の皿
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  e = a + b;
  f = c + d;
  if (e > f) {
    cout << "Left" << endl;
  }
  else if (e < f) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long INF=1000000000000000;

int main() {
    long N,K;
    cin>>N>>K;
    
    long ans=0;
    
    for(int i=0;i<N;i++){
        long x;
        cin>>x;
        
        ans+=2*min(x,K-x);
    } 
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <algorithm>
#include <unordered_map>
#include <iomanip>
#include <time.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  if(n==m)
    cout << "Yes";
  else
    cout << "No";

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

a, b = map(int, input().split())

def calc(a):
    if a <= 0: return 0
    
    # 4のときに0,1,2,3,4までになるので、これは5つの整数
    a += 1
    
    ans = 0
    # i桁目の偶奇を調べる
    # 10^3 <= 2^10
    # 10^12 <= 2進数で40桁くらい
    for i in range(50):
        
        # 0桁目 周期2, 1桁目 周期4, 2桁目 周期8
        loop = (1 << (i+1))
        cnt = a//loop * loop//2 # loopした回数×1が出てくる回数
        # 0000....001111....11
        cnt += max(0, (a%loop) - (loop//2))
        # その桁の1の数が奇数だったら足し算
        if cnt%2 == 1:
            ans += 1<<i
            
    return ans
        
ans = calc(a-1)^calc(b)

print(ans)

Measured memory_bytes: 9108
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String line;
	int[] flag = new int['Z'+1];
	int oi = 0;
	try{
	    while(null!=(line = br.readLine())){
		line = 'A' + line;
		while((oi = line.indexOf("OI")) != -1){
		    flag[line.charAt(oi-1)]++;
		    line = line.substring(oi + 1);
		}
		System.out.println(Integer.toString(flag['J']));
		System.out.println(Integer.toString(flag['I']));
		flag['J'] = flag['I'] = 0;
	    }
	}
	catch(Exception e){
	    System.out.println(e.getMessage() + oi);
	}
    }
}

Measured memory_bytes: 17896
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
constexpr double pi=3.14159265358979;

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;
}
using namespace std;


void solve(){
    double n,m,d;
    cin>>n>>m>>d;
    if(d!=0)printf("%.10lf\n",(2*(n-d)*(m-1)/(n*n)));
    else printf("%.10lf\n",((n-d)*(m-1)/(n*n)));
}

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


Measured memory_bytes: 256