akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
//#include <functional>
#include <queue>
//#include <stack>
//#include <set>
#include <cmath>
//#include <bitset>
#include <map>
using namespace std;
typedef long long ll;

struct edge{int to, weight;};
const int MAX_V = 1e6;
vector<edge> G[MAX_V];
int used[MAX_V];

//fromからtoへ向かう容量weightの辺をグラフに追加する
void add_edge(int from, int to, int weight){
  G[from].push_back((edge){to,weight});
  G[to].push_back((edge){from, weight});
}

void dfs(int v){
  for(int i=0; i < G[v].size(); i++){
    edge &e = G[v][i];
    //    cout << e.to << endl;
    if(used[e.to]==-1){
      used[e.to] = (used[v]^e.weight);
      //      cout << v << " " << e.to << endl;
      //      cout << e.weight << " " << used[e.to] << endl;
      dfs(e.to);	
    }
    else{
      continue;
    }
  }
}


int main() {
  int N;
  cin >> N;
  int u[N];
  int v[N];
  int w[N];

  for(int i=0; i<N-1; i++){
    cin >> u[i] >> v[i] >> w[i];
    add_edge(u[i]-1,v[i]-1,w[i]%2);
  }
  //  cout << G[1][0].weight << endl;
  memset(used, -1 ,sizeof(used));
  //  cout << (1^1) << (1^0) << (0^0) << endl;
  //  cout << "here " << endl;
  used[0]=0;
  dfs(0);
  for(int i=0; i<N; i++){
    cout << used[i] << endl;
  }
  return 0;

}


Measured memory_bytes: 34048
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt(), b=sc.nextInt(), c=sc.nextInt();
		System.out.println(b-a==c-b ? "YES" : "NO");
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35864
import java.util.Scanner;

  class Main {
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b  =scan.nextInt();
        int c = scan.nextInt();
        int z = scan.nextInt();
        int count = 0 ;
        for(int i = 0 ; i <=a ; i++){
            for(int j = 0 ; j<=b ; j++){
                 
                for(int k = 0 ; k<=c ; k++){
                    int sum = 500*i+100*j+50*k ;
                    if(sum == z){
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  vector<int> Y(N);
  for(int i = 0 ;i < N ;i++){
    cin >> X.at(i);
    Y.at(i) = X.at(i);
  }
  sort(X.begin(),X.end());
  int A = X.at(N/2-1),B = X.at(N/2);
  
  for(int k = 0;k < N;k++){
    if(Y.at(k) <= A){
      cout << B << endl;
    }
    if(Y.at(k) > A){
      cout << A << endl;
    }
  }
 
  
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int n,q,xl,xr,res;
int a[1000010],cnt[1000010],ans[1000010];
struct Node{
	int l,r,num;
}f[1000010];
inline bool cmp(Node a,Node b){
	if(a.l/1000==b.l/1000)
		return a.r<b.r;
	return a.l<b.l;
}
inline void Add(int x){
	if(cnt[x]==0)
		res++;
	cnt[x]++;
}
inline void Delete(int x){
	if(cnt[x]==1)
		res--;
	cnt[x]--;
}
int main(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=q;i++){
		scanf("%d%d",&f[i].l,&f[i].r);
		f[i].num=i;
	}
	sort(f+1,f+q+1,cmp);
	xl=1,xr=1,res=1;
	cnt[a[1]]=1;
	for(int i=1;i<=q;i++){
		while(xl<f[i].l){
			Delete(a[xl]);
			xl++;
		}
		while(xl>f[i].l){
			xl--;
			Add(a[xl]);
		}
		while(xr<f[i].r){
			xr++;
			Add(a[xr]);
		}
		while(xr>f[i].r){
			Delete(a[xr]);
			xr--;
		}
		ans[f[i].num]=res;
	}
	for(int i=1;i<=q;i++)
		printf("%d\n",ans[i]);
	return 0;
}

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

int main() {
	// your code goes here
	int yen;
	cin>>yen;
	int points;
    int d,r;
    d=yen/500;
    r=yen%500;
    r=r/5;
    points=d*1000+r*5;
    cout<<points;
	return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    String s = sc.next();
    pw.println(s.endsWith("s") ? s + "es" : s + "s");
  }
}


Measured memory_bytes: 38568
import sys
input=sys.stdin.readline
N=int(input())
S=input()
Q=int(input())
D={}
A=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(26):
    D[A[i]]=i
n=1
while n<N:
    n*=2

seg=[0 for i in range(n*2)]
#print(seg)

for i in range(N):
    seg[n-1+i]=1<<D[S[i]]
    k=n-1+i
    while k>0:
        k=(k-1)//2
        seg[k]=(seg[k*2+1]|seg[k*2+2])
#print(list(bin(seg[0])).count("1"))

#0indexでa番目の値をbに変更
def update(a,b):
    a+=n-1
    seg[a]=1<<D[b]
    while a>0:
        a=(a-1)//2
        seg[a]=(seg[a*2+1]|seg[a*2+2])

#print(seg)

#A～B-1(0-index)までの累積和を求める
#1～2までの累積和なら(1,3,0,0,n)
#Kは接点番号？L,Rはその接点が[L,R)に対応づいていることを表す？
#外部からはquery(A,B,0,0,n)として呼び出す
def query(A,B,K,L,R):
    if K>=len(seg):
        return 0
    if R<=A or B<=L:
        return 0
    elif A<=L and R<=B:
        return seg[K]
    else:
        vl=query(A,B,K*2+1,L,(L+R)//2)
        vr=query(A,B,K*2+2,(L+R)//2,R)
        #print(vl,vr)
        return vl|vr
#print(n,len(seg))
#print("P",query(2,4,0,0,n),len(query(2,4,0,0,n)))
#update(3,"a")
#print(seg)
#print(query(2,4,0,0,n))
for i in range(Q):
    x,y,z=list(input().split())
    if x=="1":
        update(int(y)-1,z)
    else:
        print(list(bin(query(int(y)-1,int(z),0,0,n))).count("1"))


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

const double EPS = 1e-10;
const double PI = acos(-1.0);

int sign(double x) {  //???????????°???????°???????????¢?
    return abs(x) < EPS ? 0 : x < 0 ? -1 : 1;
}

struct Point { //????????????
    double x, y;
    Point(double x=0.0, double y=0.0) : x(x), y(y) {}
    Point operator + (const Point &rhs) const {  //????????????
        return Point(x + rhs.x, y + rhs.y);
    }
    Point operator - (const Point &rhs) const {  //????????????
        return Point(x - rhs.x, y - rhs.y);
    }
    Point operator * (double p) const {  //???????????\??????
        return Point(x * p, y * p);
    }
    Point operator / (double p) const {  //???????????\??????
        return Point(x / p, y / p);
    }
    bool operator < (const Point &rhs) const {  //??????????????????
        return x < rhs.x || (x == rhs.x && y < rhs.y);
    }
    bool operator == (const Point &rhs) const {  //??????????????????
        return sign(x - rhs.x) == 0 && sign(y - rhs.y) == 0;
    }
    void read() {
        scanf("%lf%lf", &x, &y);
    }
    void print() {
        printf("(%.2f, %.2f)\n", x, y);
    }
};
typedef Point Vector;  //???????????????

double dot(Vector A, Vector B) {  //??????????§???????????????????????§??????????????§??????????????????????????????????????§????
    return A.x * B.x + A.y * B.y;
}
double cross(Vector A, Vector B) {  //??????????§??????????????????????????§???¢???????????¢?§????????????????????????????????????????
    return A.x * B.y - A.y * B.x;
}
double polar_angle(Vector A) {  //??????????§?
    return atan2(A.y, A.x);
}
double length(Vector A) {  //???????????????????§?
    return sqrt(dot(A, A));
}
double angle(Vector A, Vector B) {  //????????¬?§?????????¶??????????§?
    return acos(dot(A, B)/length(A)/length(B));
}
Vector rotate(Vector A, double rad) {  //???????????¬????????¶???
    return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
    //????????´?????¬????????¶????????????????????¢??¬??????x'=xcos(theta)+ysin(theta), y'=ycos(theta)-xsin(theta)
}
Vector normal(Vector A) {  //?????????????????????????????????A????????¶??????
    double len = length(A);
    return Vector(-A.y/len, A.x/len);
}
bool on_seg(Point p, Point a, Point b) {  //???????????¨??????????????????????????????????????????
    return sign(cross(a-p, b-p)) == 0 && sign(dot(a-p, b-p)) < 0;  //???p????????¨??????ab???
}
Point point_line_proj(Point p, Point a, Point b) {  //?????¨??´??????????????±????????????
    Vector V = b - a;
    return a + V * (dot (V, p-a)/dot(V, V));  //???p??°??´???ab????????±
}

int main() {
    Point p0, p1;
    p0.read();
    p1.read();
    int q; scanf("%d", &q);
    while(q --) {
        Point p2;
        p2.read();
        double alpha = cross(p2-p0, p1-p0);
        if(sign(alpha) > 0) puts("CLOCKWISE");
        else if(sign(alpha) < 0) puts("COUNTER_CLOCKWISE");
        else {
            if(on_seg(p0, p1, p2)) puts("ONLINE_BACK");
            else if(on_seg(p1, p0, p2)) puts("ONLINE_FRONT");
            else puts("ON_SEGMENT");
            
        }
    }
}

Measured memory_bytes: 3240
#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x)
{
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar('\n');
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y, 0); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int N = 1005000;
char s[N];
int bit[N], sum;
int main() {
	scanf ("%s", s + 1); int n = strlen(s + 1);
	reverse(s + 1, s + n + 1);
	for (int j = 1;j <= n; j++) {
		bit[j] += (int)(s[j] - '0') * 9;
		bit[j + 1] += bit[j] / 10, bit[j] %= 10;
		sum += bit[j];
	}
	if (bit[n + 1]) sum += bit[++n];
	n += 5000;
	for (int k = 1;k <= n; k++) {
		sum -= bit[1], bit[1] += 9;
		for (int j = 2;j <= n + 1; j++) {
			if (bit[j - 1] >= 10) 
				sum -= bit[j], bit[j]++, bit[j-1] -= 10, sum += bit[j-1];
			else { sum += bit[j-1]; break; }
		}
		if (sum <= 9 * k) return write(k), 0;
	}
	return 0;
}

Measured memory_bytes: 6200
import fractions
total = 0
A = int(input())
listB = list(map(int,input().split()))
if 1 < A:
    B = listB[0] * listB[1] // fractions.gcd(listB[0],listB[1])
    for i in range(A-2):
        B = listB[i+2] * B // fractions.gcd(B,listB[i+2])
else:
    B = listB[0]
for i in listB:
    total += B // i
print(B / total)

Measured memory_bytes: 5428
package main

import (
	"fmt"
	//"math"
	//"math"
	//"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	if s <= "2019/04/30" {
		fmt.Println("Heisei")
	} else {
		fmt.Println("TBD")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int a[1000000];
int main()
{
    int k,s;
    cin>>k>>s;
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<=k;j++)
        {
            a[5000+i+j]++;
        }
    }
    int sum=0;
    for(int i=0;i<=k;i++)
    {
        int pos=s-i;
        if(pos<0)
        {
            continue;
        }
        sum+=a[5000+pos];
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int n = scan.nextInt();

		int R1 = scan.nextInt();
		int R2 = scan.nextInt();

		int gap = R2 - R1;
		int min = Math.min(R1, R2);
		for (int i = 2; i < n; i++) {
			int R = scan.nextInt();
			if (R - min > gap)
				gap = R - min;
			if (R < min)
				min = R;
		}
		System.out.println(gap);
		
		scan.close();
		System.exit(0);
	}

}

Measured memory_bytes: 99784
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int n;
    cin>>n;
    vector<int>v(n);
    int f=0;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    sort(v.begin(),v.end(),greater<int>());
    ll sum=0;
    for(int i=1;i<n;i++)
    {
       sum+=v[i/2];
    }
    cout<<sum<<endl;







}





































































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

int main(){
  string S;
  cin >> S;
  for(int i=0;i<3;i++){
    if(S.at(i) == S.at(i+1)){
      cout << "Bad" << endl;
      break;
    }
    else if(S.at(i) != S.at(i+1) && i==2)
      cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
N,K = map(int, input().split())
a = []
d = {}
for i in range(N):
    ls = list(map(int, input().split()))
    if ls[0] in d:
        d[ls[0]] = d[ls[0]] + ls[1]
    else:
        d[ls[0]] = ls[1]
d = sorted(d.items())
cnt = 0
for t in d:
    cnt += t[1]
    if cnt >= K:
        print(t[0])
        break

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

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

Measured memory_bytes: 3576
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
vector<vector<int>> graph;
int n,m;
int main(){
int x,y;
cin>>n>>x>>y;
vector<ll> d;
graph.resize(n);
for(int i=0;i<n-1;i++){
    graph[i].emplace_back(i+1);
     graph[i+1].emplace_back(i);
}
graph[x-1].emplace_back(y-1);
graph[y-1].emplace_back(x-1);
V<ll> ans(n+1,0);
for(int i=0;i<n;i++){
    d.assign(n,inf);
    d[i]=0;
    queue<int> q;
    q.push(i);
    while(q.size()){
        int now=q.front();
        q.pop();
        for(int v:graph[now]){
            if(d[v]>d[now]+1){
                d[v]=d[now]+1;
                q.push(v);
            }
        }
    }
    for(int j=i;j<n;j++)if(d[i]<=n)ans[d[j]]++;
}
for(int i=1;i<n;i++){
    cout<<ans[i]<<"\n";
}

}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if((a<c && c<b) || (a>c && c>b)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N=int(input())
S=[0 if i=="." else 1 for i in input()]
X=[0 for i in range(N+1)]
Y=[0 for i in range(N+1)]
for i in range(N):
    X[i+1]=S[i]+X[i]
    Y[-2-i]=Y[-1-i]+(1-S[-1-i])
Z=[X[i]+Y[i] for i in range(N+1)]
print(min(Z))


Measured memory_bytes: 28640
#template
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
A = inputlist()
co =0
for i in range(N):
    if A[i] % 2 == 1:
        co+=1
if co % 2 == 0:
    print("YES")
else:
    print("NO")

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

using namespace std;

#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;


int main()
{
    //freopen("input.txt", "r", stdin);


    ll a, b, n;
    cin >> a >> b >> n;
    if (n >= b - 1) n = b - 1;
    cout << (a * n) / b;

}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(all(a));
  for (int i = 0; i < n; i++) {
    cout << a[i].second << (i == n - 1 ? '\n' : ' ');
  }
  return 0;
}

Measured memory_bytes: 3960
def main():
    l,r,d = map(int,input().split())
    ls = [i for i in range(l,r+1)]
    ans = 0
    for i in range(len(ls)):
        if ls[i]%d==0:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9168
N = int(input())

N3 = N//3
N5 = N//5
N15 = N//15

print(N*(N + 1)//2 - 3*N3*(N3 + 1)//2 - 5*N5*(N5 + 1)//2 + 15*N15*(N15 + 1)//2)


Measured memory_bytes: 9164
a = list(input())
b = list(input())
c = list(input())

win = False # if win == True, someone will win
run = a

while win != True:
  if run[0] == "a":
    run.pop(0)
    run = a # reset run
    if len(a) == 0:
      print("A")
      win = True
  elif run[0] == "b":
    run.pop(0)
    run = b
    if len(b) == 0:
      print("B")
      win = True
  else:
    run.pop(0)
    run = c
    if len(c) == 0:
      print("C")
      win = True





Measured memory_bytes: 9064
#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>;

const double PI = acos(-1);

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double th = double(h*60+m)/720 * 2*PI;
  double tm = double(m)/60 * 2*PI;
  double xh = a*cos(th), yh = a*sin(th);
  double xm = b*cos(tm), ym = b*sin(tm);
  double dx = xh-xm, dy = yh-ym;
  double ans = sqrt(dx*dx + dy*dy);
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 4128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007;
int main() {
    ll n, k, ans, cases;
    //cin >> cases;
	//while(cases--){
        cin >> n >> k;
        ans = 0;
        for(int i = k; i <= n + 1; i++) {
            ans += (((n - i + 1) * i + 1) % mod);
            ans %= mod;
        }
        cout << ans << "\n";
	//}
	return 0;
}


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


int main(){
    ios_base::sync_with_stdio(false);
    ll a,b,k;
    cin>>a>>b>>k;
    if(a-k>=0) {
        cout << a - k << ' ' << b;
    }else{
        cout<<0<<' '<<max(b+(a-k),(ll)0);
    }


}


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

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)


int main() {
  int l,r;
  cin >> l >> r;
  int g = r - l;
	l %= 2019;
	r %= 2019;
	int ans = 2020;
	int m = 2020;
	if (l < r )FOR(i,l,r) FOR(j,i+1,r+1) ans = min(ans, (i*j)%2019);
	else ans = 0;
	if (g >= 2019)ans = 0;

  cout << ans << endl;
}

Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main(){
    int n,count=0;
    cin >> n;
    int l[100];
    for(int i = 0; i<n; i++){
        cin >> l[i];
    }
    for(int i = n-1; i > 0 ; i--){
      for(int j = 0; j<i; j++){
        if (l[j]>l[j+1]){
          l[j] += l[j+1];
          l[j+1] = l[j] - l[j+1];
          l[j] = l[j] -l[j+1];
          count++;
        }   
      }
    }
    for(int k = 0 ; k<n-1 ;k++){
        cout<<l[k]<<" ";
    }
    cout<<l[n-1]<<endl;
    cout<<count<<endl;
}


Measured memory_bytes: 3084
#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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int a; cin >> a;
  int array[4];
  for(int i = 3; i >= 0; --i) {
    array[i] = a % 10;
    a/=10;
  }

  rep(i, 1<<3) {
    vector<bool> v;
    rep(j, 3) {
      v.push_back(i >> j & 1);
    }
    int sum = array[0];
    rep(j, 3) {
      sum += (array[j+1] * (v[j] ? 1 : -1));
    }
    if(sum == 7) {
      rep(k, 3) {
	cout << array[k] << (v[k] ? '+' : '-');
      }
      cout << array[3] << "=7" << endl;
      return 0;
    }
  }
}
      


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

int v[10][300000],w[10][100000];

signed main(){
  int n;cin>>n;
  string s;cin>>s;
  set<int> se;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      v[j][i+1]=v[j][i]+(s[i]==('0'+j));
      w[j][n-i]=w[j][n-i+1]+(s[n-i-1]==('0'+j));
    }
  }
  for(int i=1;i<n-1;i++){
    for(int j=0;j<10;j++){
      for(int k=0;k<10;k++){
        if(v[j][i]&&w[k][i+2]){
          se.insert((j*100+(s[i]-'0')*10+k));
        }
      }
    }
  }
  cout<<se.size()<<endl;
}


Measured memory_bytes: 29696
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main(void) {
    string S, T;
    cin >> S >> T;
    int ans = 0;
    for(int i=0; i<S.size(); i++) {
        if(S[i] != T[i]) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3916
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[100000];
	int n, num = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	printf("%d", a[n / 2] - a[n / 2 - 1]);
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++){
    cin >>A[i];
  }
  int M1 = A[0];
  int M2 = A[1];

  for(int j=1;j<N;j++){
        if(M1<=A[j]){
          M2 = M1;
          M1 = A[j];
        }else if(M2<A[j]){
          M2=A[j];
        }
  }

  for(int i=0;i<N;i++){
    if(A[i]==M1){
      cout<<M2<<endl;
    }else{
      cout<<M1<<endl;
    }
  }
}


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

int main(){
    ll n, m;
    cin >> n >> m;
    ll a[n], b[n];
    for(int i =0; i<n; i++){
        cin >> a[i]>> b[i];
    }

    pair<ll, ll> p[n];
    for(int i =0; i<n; i++){
        p[i].first=a[i];
        p[i].second=b[i];
    }
    sort(p, p+n);
    ll ans=0;
    for(int i = 0; i < n; i++){
        ans+=min(m, p[i].second)*p[i].first;
        m-=min(m, p[i].second);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	int H,W; cin >> H >> W;
	char s[51][51];
	int d[51][51];
	int count = 0;
	rep(i,H)rep(j,W){
		cin >> s[i][j];
		d[i][j]=INF;
		if (s[i][j]=='.')count++;
	}
	queue <P> Q;
	d[0][0] = 0;
	Q.push({0,0});
	
	while (!Q.empty()) {
		int y = Q.front().first;
		int x = Q.front().second;
		Q.pop();
		for (int i = 0; i < 4; ++i) {
			int ny = y + dy[i];
			int nx = x + dx[i];
			if (0 <= ny && ny < H && 0 <= nx && nx < W && s[ny][nx] == '.' && d[ny][nx] == INF) {
				Q.push({ny,nx});
				d[ny][nx] = d[y][x] + 1;
			}
		}
	}
	if (d[H-1][W-1]==INF) cout << -1 << endl;
	//マス目全体の白いマスの個数-けぬす君が通る白いマスの個数
	else cout << count-(d[H-1][W-1]+1) << endl;
	return 0;
}

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


template <class T>
ostream& operator <<(ostream& os, vector<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

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

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A_list(N);
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        A_list.at(i) = tmp;
    }
    vector<int> prefix_gcd(N);
    int cur_gcd = A_list.at(0);
    prefix_gcd.at(0) = cur_gcd;
    for (int i = 1; i < N; i++) {
        cur_gcd = gcd(cur_gcd, A_list.at(i));
        prefix_gcd.at(i) = cur_gcd;
    }
    vector<int> suffix_gcd(N);
    cur_gcd = A_list.at(N - 1);
    suffix_gcd.at(N - 1) = cur_gcd;
    for (int i = N - 2; i >= 0; i--) {
        cur_gcd = gcd(cur_gcd, A_list.at(i));
        suffix_gcd.at(i) = cur_gcd;
    }
    // cout << prefix_gcd << "\n";
    // cout << suffix_gcd << "\n";
    int max_gcd = suffix_gcd.at(1);
    for (int i = 0; i < N - 2; i++) {
        max_gcd = max(max_gcd, gcd(prefix_gcd.at(i), suffix_gcd.at(i + 2)));
    }
    max_gcd = max(max_gcd, prefix_gcd.at(N - 2));
    cout << max_gcd << "\n";
}

Measured memory_bytes: 1408
#include <cstdio>
#define rep(i,n) for(int i=0; i<n; ++i)
	
int n,m,l;

int main(){
	scanf("%d %d %d", &n,&m,&l);
	
	int a[n][m];
	rep(i,n){
		rep(j,m){
			scanf("%d", &a[i][j]);
		}
	}
	
	int b[m][l];
	rep(i,m){
		rep(j,l){
			scanf("%d", &b[i][j]);
		}
	}
	
	int long long c[n][l];
	rep(i,n){
		rep(j,l){
			int long long x=0;
			rep(k,m){
				x+=a[i][k]*b[k][j];
			}
			c[i][j]=x;
		}
	}
	
	rep(i,n){
		rep(j,l-1){
			printf("%lld ", c[i][j]);
		}
		printf("%lld\n", c[i][l-1]);
	}
}


Measured memory_bytes: 2832
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        for (int i = 1; i <= N; i++) {
            if (i % 2 == 0) {
                continue;
            }
            int c = 0;
            for (int j = 1; j <= i; j++) {
                if (i % j == 0) {
                    c++;
                }
            }
            if (c == 8) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
// 素因数分解
vector<pair<long long, long long>> prime_factorize(long long n)
{
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p)
  {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0)
    {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}
int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> sv(m), cv(m);
  rep(i, m)
  {
    cin >> sv[i];
    sv[i]--;
    cin >> cv[i];
  }
  for (int ans = 0; ans <= 999; ans++)
  {
    string s = to_string(ans);
    bool ok = true;
    if (s.length() != n)
    {
      ok = false;
    }
    for (int i = 0; i < m; i++)
    {
      for (int j = 0; j < n; j++)
      {
        if ((s[sv[i]]) != cv[i] + '0') // '0'を足すと文字へ'0'を引くと数字へ
        {
          ok = false;
        }
      }
    }
    if (ok)
    {
      cout << ans << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
int n,m;
int a[100][100];
int b[100];
int c[100];
void proc(){
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      c[i]+=a[i][j]*b[j];
    }
    printf("%d\n",c[i]);
  }
}

void inp(){
  scanf("%d%d",&n,&m);
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(int j=0;j<m;j++){
    scanf("%d",&b[j]);
  }
}

int main(){
  inp();
  proc();
  return 0;
}

Measured memory_bytes: 1048
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)
typedef long long ll;

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}


int main() {

	int N;
	cin >> N;

	vector<char> inputs;
	int W_count = 0;
	int R_count = 0;

	for (int i = 0; i < N; i++) {
		char tmp;
		cin >> tmp;
		inputs.push_back(tmp);
		if (tmp == 'R') R_count++;
		if (tmp == 'W') W_count++;
	}

	int ans = 0;
	for (int i = 0; i < R_count; i++) {
		if (inputs[i] == 'W') ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3740
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<x<<" ";}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
//#define int long long 
#define lb lower_bound
#define mkp make_pair
//#define d double
vl fac(5000001);
ll g(ll r,ll c){
	if(r<0 || c<0) return 0;
	ll ans = 0;
	for(int i=1;i<=r+1;i++){
		ans = (ans + fac[c+i]*mi(fac[i],mod)%mod)%mod;
	}
	ans = ans*mi(fac[c],mod)%mod;
	ans%=mod;
	return ans;
}
void solve(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	fac[0]=1;
	for(int i=1;i<=5000000;i++) fac[i]=fac[i-1]*i%mod;
	ll ans=(g(c,d)-g(a-1,d)-g(c,b-1)+g(a-1,b-1)+mod)%mod;
	
	cout<<ans<<endl;
	
	
	
}
int32_t main(){
int t=1;
//cin>>t;
while(t--){
	solve();
}
}

Measured memory_bytes: 39296
h,w = map(int,input().split())
grid1 = [['#'] * (w+2) for i in range(h+2)]
grid2 = [[0] * (w+2) for i in range(h+2)]
for i in range(h):
  grid1[i+1][1:-1] = list(input())
for i in range(1,h+1):
  for j in range(1,w+1):
    if i == j == 1:
      grid2[i][j] = 1
    elif grid1[i][j] == '.':
      grid2[i][j] = (grid2[i-1][j] + grid2[i][j-1]) % (10**9+7)
print(grid2[h][w])

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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N=nextInt();

		int[] A = nextInts();
		int[] n = new int[N];
		HashMap<Integer,Integer> map = new HashMap<>();
		for(int i=0;i<N;i++){
			map.put(i+1-A[i],map.getOrDefault(i+1-A[i], 0)+1);
		}
		long ans = 0;
		for(int i=0;i<N;i++){
			ans+=map.getOrDefault(i+1+A[i],0);
		}
		System.out.println(ans);

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 65192
package main

import "fmt"

func main() {
	var K, N, max int
	fmt.Scan(&K, &N)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&a[i])
	}

	max = K - a[N-1] + a[0]
	for i := 1; i < N; i++ {
		max = Max(max, a[i]-a[i-1])
	}
	fmt.Println(K - max)
}
func Max(a, b int) int {
	if b > a {
		return b
	}
	return a
}


Measured memory_bytes: 6656
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int n;
	
	cin >> n;
	
	if(n % 10 == 9 or n/10 == 9) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


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

int main() {
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    double ans = w * h / 2;
    cout << fixed << setprecision(10);
    cout << ans << " ";
    if (w == 2 * x && h == 2 * y)
        cout << 1 << endl;
    else
        cout << 0 << endl;
    return 0;
}

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

typedef struct Process{
  char name[100];
  int time;
} P;

class myQueue{
public:
  myQueue(int n){
    data = new P[n];
    head = 0;
    tail = 0;
    MAX = n;
  }
  ~myQueue(){
    //delete [] data;
  }
  void enqueue(P x){
    data[tail] = x;
    if(tail+1 == 100005) tail = 0;
    else tail++;
  }
  P dequeue(){
    P x = data[head];
    if(head+1 == 100005) head = 0;
    else head++;
    return x;

  }
  void PrintQueue(){
    for(int i=0;i<MAX;i++){
      cout << data[i].name << " " << data[i].time << endl;
    }
  }
  bool isEmpty(){
    return head == tail;
  }

private:
  P *data;
  int head, tail;
  int MAX;
};

int main(){
  int n, q;
  cin >> n >> q;
  myQueue queue(100005);
  P p;
  for(int i=0;i<n;i++){
    cin >> p.name >> p.time;
    queue.enqueue(p);
    //queue.PrintQueue();
  }
  //cout << n << " " << q << endl;
  //queue.PrintQueue();

  int t = 0;
  while(!queue.isEmpty()){
    p = queue.dequeue();
    if(p.time >= q){
      t += q;
      p.time -= q;
    }
    else{
      t += p.time;
      p.time = 0;
    }

    if(p.time <=0){
      printf("%s %d\n", p.name, t);
      //cout << p.name << " " << t << endl;
    }
    else{
      queue.enqueue(p);
    }
  }
  return 0;
}



Measured memory_bytes: 13196
#include<stdio.h>
#define M 10000

int search(int A[],int se,int n){
  int i;

  for(i = 0;i<n;i++){
    if(A[i]==se)return 1;
  }
  return 0;
}


int main(){
  int i,q,n,A[M+1],se,count=0,g;

  scanf("%d",&n);
  if(n>M)return 0;

  for(i =0;i<n;i++)
    scanf("%d",&A[i]);
  
  scanf("%d",&q);
  if(q>500) return 0;

  for(i = 0;i<q;i++){
    scanf("%d",&se);
    g = search(A,se,n);
    if(g == 1) count++;
  }
  printf("%d\n",count);
  return 0;

}



Measured memory_bytes: 2036
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
	int w=sc.nextInt();
	int n=sc.nextInt();
	int[] values=new int[w];
	for(int i=0;i<values.length;i++){
	values[i]=i+1;
	}
	for(int i=0;i<n;i++){
	String str=sc.next();
	String[] ab=str.split(",");
	int a=Integer.parseInt(ab[0])-1;
	int b=Integer.parseInt(ab[1])-1;
	int c;
	c=values[a];
	values[a]=values[b];
	values[b]=c;
	}
	for(int i=0;i<values.length;i++){
		System.out.println(values[i]);
	}
	}
}

Measured memory_bytes: 26164
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from itertools import product
import sys
INF = 10**16
def main(N, A):
    dp = [[[-INF] * 2 for __ in range(3)] for _ in range(N + 1)]
    dp[0][1][0] = dp[0][2][0] = 0
    for i in range(1, N + 1):
        pi = ((i - 1) // 2 - 1, (i - 1) // 2, i // 2)
        ni = (i // 2 - 1, i // 2, (i + 1) // 2)
        for pii, nii, pk, nk in product(range(3), range(3), range(2), range(2)):
            pj, nj = pi[pii], ni[nii]
            if pj > nj or pj + 2 <= nj: continue
            if pj == nj and nk == 1: continue
            if pj < nj and nk == 0: continue
            if pk == 1 and nk == 1: continue
            if dp[i - 1][pii][pk] == -INF: continue
            dp[i][nii][nk] = max(dp[i][nii][nk], dp[i - 1][pii][pk] + (A[i - 1] if nk == 1 else 0))
    ans = -INF
    for k in range(2):
        ans = max(ans, dp[N][1][k])
    print(ans)

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)


Measured memory_bytes: 172068
#pragma warning( disable : 6031)

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <math.h>
int minimum(int a, int b) { return a < b ? a : b; }
int maximum(int a, int b) { return a > b ? a : b; }
const long long mod = 1000000007;
//const long long mod = 998244353;
using std::vector;
using std::pair;
using std::string;
using std::map;
using std::abs;
int main() {
	int N, M, X;
	scanf("%d %d %d", &N, &M, &X);
	auto C = new int[N];
	auto A = new int*[N];
	for (int i = 0; i < N; i++) {
		A[i] = new int[M];
		scanf("%d", C + i);
		for (int j = 0; j < M; j++) {
			scanf("%d", A[i] + j);
		}
	}
	auto B = new int[M];
	int min = mod;
	for (int i = 0; i < (1 << N); i++) {
		for (int j = 0; j < M; j++)B[j] = 0;
		int cost = 0;
		for (int j = 0; j < N; j++) {
			if (i & (1 << j)) {
				for (int k = 0; k < M; k++) {
					B[k] += A[j][k];
				}
				cost += C[j];
			}
		}
		bool ok = true;
		for (int j = 0; j < M; j++) {
			if (B[j] < X) {
				ok = false;
				break;
			}
		}
		if (ok) {
			min = minimum(min, cost);
		}
	}
	printf("%d", min == mod ? -1 : min);
	return 0;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = __INT_MAX__;               // 2^31 - 1
const long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

struct mint {
    // Preparation: MOD is already defined.
    ll value;

    mint(ll value = 0) : value((value % MOD + MOD) % MOD) {}

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(mint m) const {
        return pow(m.value);
    }

    mint inv() const {
        ll a = value, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        return u;
    }

    mint &operator+=(const mint a) {
        if ((value += a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((value += MOD - a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (value *= a.value) %= MOD;
        return *this;
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
// moving 4-direction
int dx[] = {1, 1, 1, -1, -1, -1, 0, 0};
int dy[] = {1, 0, -1, 1, 0, -1, 1, -1};
mint dp[1005][1005];
char maze[1005][1005];

int main() {
    int h, w;
    cin >> h >> w;
    rep(i, h) {
        rep(j, w) {
            cin >> maze[i][j];
        }
    }

    rep(i, h) {
        if (maze[i][0] == '#') break;
        dp[i][0] = 1;
    }
    rep(i, h) {
        if (maze[0][i] == '#') break;
        dp[0][i] = 1;
    }

    rep(i, h) {
        rep(j, w) {
            if (maze[i + 1][j] == '.' && j < w) dp[i + 1][j + 1] += dp[i + 1][j];
            if (maze[i][j + 1] == '.' && i < h) dp[i + 1][j + 1] += dp[i][j + 1];
        }
    }
    out(dp[h - 1][w - 1].value);
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int arr[N];
    vector<int>dp(N,0);
    
    for(int i=0;i<N;i++){
    cin >> arr[i];
    }
    if(N>1)
        dp[1] = abs(arr[1] - arr[0]);
    
    for(int i=2;i<N;i++){
       dp[i] = min(dp[i-1]+abs(arr[i] - arr[i-1]), dp[i-2]+abs(arr[i-2]-arr[i]));
    }
    
    cout << dp[N-1] <<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;

using namespace std;

string input;
ll ans = 0;

void solve(string s)
{
    int i = 0;
    string num = ""; 
    ll sum = 0;
    s += "+";

    while(i < s.size()){
        if(s[i] != '+') {
            num += s[i];
        } else {
            if(num.size() > 9) {
                sum += (num[0]-'0') * 1e9;
                sum += stoi(num.substr(1, 9));
            } else {
                sum += stoi(num);
            }
            num = "";
        }
        i++;
    }
    ans += sum;
}

void make_string(int bit)
{
    int i = 0;
    string t("");
    irep(j, input.size()) {
        t += input[j];
        if(bit & (0x1 << j)) {
            t += "+";
        }
    }
    //t += input.back();
    //cout << t << endl;
    solve(t);
}

void make_bit(int n, int i, int bit)
{
    if(n == i) { 
        //cout << bit << endl;
        make_string(bit); 
        return;
    }
    make_bit(n, i+1, bit);
    make_bit(n, i+1, bit | (0x1 << i));
}

int main() 
{
    cin >> input;
    
    make_bit(input.size()-1, 0, 0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 1000000007 //998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define PI 3.141592653589793238
#define pq priority_queue<ll>
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}
void solve()
{
  ll n,p;
  cin>>n>>p;
  
  ll a[n];
  for(ll i=0;i<n;i++)
  cin>>a[i];
  
  ll ev=0;
  ll od=0;
  
  for(ll i=0;i<n;i++){
      if(a[i]%2==0)
      ev++;
      else
      od++;
  }
  
  
  ll ans=0;
  
   if(p==0){
       if(od==0)
       ans=(1LL<<n);
       else
       ans=(1LL<<(n-1));
   }
   else{
       if(od==0)
       ans=0;
       else
       ans=(1LL<<(n-1));
   }
   
   cout<<ans<<endl;
}
int32_t main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
//Start from Here.

  ll t;
  t=1;
 // cin>>t;
  while(t--)
  solve();
  
//Good Bye!
    return 0;
}

Measured memory_bytes: 3628
N,M = map(int,input().split())
S = input()
T = input()

def gcd(a,b):
    if a == 0:
        return b
    else:
        return gcd(b%a,a)

G = gcd(N,M)
n = N//G
m = M//G

ans = -1
i = 0
while i*n < N:
    if S[i*n] != T[i*m]:
        break
    i+=1
else:
    ans = N*M//G

print(ans)


Measured memory_bytes: 3316
n,m=map(int,input().split())
lists=list(map(int,input().split()))
sumslist=[0 for i in range(n+1)]
sums=0
for j in range(n):
    sums+=lists[j]
    sumslist[j+1]=sums%m
import collections
dictionary=dict(collections.Counter(sumslist))
answer=0
for j in dictionary.values():
    answer+=j*(j-1)//2
print(answer)
    

Measured memory_bytes: 18076