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

int main()
{
    int n,rem,flag=0;
    cin>>n;
    while(n>0)
    {
        rem=n%10;
        n=n/10;
        if(rem==7)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define endl '\n'

int main(void){
    string s,str,str2;
    int q;
    cin >> s >> q;
    
    itn back = 0;
    for(int i = 0;i < q;i++){
        int t;
        cin >> t;
        if(t == 1)back++,back %= 2;
        else {
            int f;
            char c;
            cin >> f >> c;
            f--;
            if((f+back) % 2 == 0)str += c;
            else str2 += c;
        }
    }
    
    reverse(str.begin(),str.end());
    s = str + s + str2;
    if(back == 1)reverse(s.begin(),s.end());
    cout << s << endl;
}

Measured memory_bytes: 1348
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var rs = new int[h[0] - 1].Select(_ => read()).ToArray();
		map = new int[h[0] + 1].Select(_ => new List<int>()).ToArray();
		foreach (var r in rs)
		{
			map[r[0]].Add(r[1]);
			map[r[1]].Add(r[0]);
		}
		ops = new int[h[1]].Select(_ => read()).GroupBy(a => a[0]).ToDictionary(g => g.Key, g => g.Sum(a => a[1]));

		c = new int[h[0] + 1];
		FindPoints(1, 0);
		Console.WriteLine(string.Join(" ", c.Skip(1)));
	}

	static List<int>[] map;
	static Dictionary<int, int> ops;
	static int[] c;

	static void FindPoints(int p, int p0)
	{
		c[p] = c[p0] + (ops.ContainsKey(p) ? ops[p] : 0);
		foreach (var q in map[p]) if (q != p0) FindPoints(q, p);
	}
}


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

int main()
{
    int h,w;cin>>h>>w;
    vector<vector<char>> c(h,vector<char> (w));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++) {
            cin>>c[i][j];
        }
        for(int j = 0; j < w; j++) {
            cout << c[i][j];
        }
        cout << endl;
        for(int j = 0; j < w; j++) {
            cout << c[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,k,i,ans=0;
    cin>>n>>k;
ll ar[n];
for(i=0;i<n;i++)
    cin>>ar[i];
sort(ar,ar+n);
for(i=0;i<k;i++)
{
    ans+=ar[i];
}

        cout<<ans<<endl;


    return 0;
}




Measured memory_bytes: 3624
#include <stdio.h>
int main(){

  int a[100];
  int i,n;

  scanf("%d",&n);

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

  for(i=n;i>0;i--){
    printf("%d",a[i-1]);
    if(i==1) break;
    else printf(" ");
  }

  printf("\n");

  return 0;
}

Measured memory_bytes: 600
import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    k, q = map(int, input().split())
    d = list(map(int, input().split()))

    for qi in range(q):
        n, x, m = map(int, input().split())
        last = x
        eq = 0
        for i in range(k):
            num = (n-1)//k
            if (n-1) % k >= i+1:
                num += 1  # numはd_iが足される回数
            last += (d[i] % m)*num
            if d[i] % m == 0:
                eq += num

        ans = (n-1)-(last//m-x//m)-eq
        print(ans)


resolve()

Measured memory_bytes: 45656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{    
    
    public void slove()
    {
        var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int a = inputs[0];
        int b = inputs[1];
        if(a <= 0 && 0 <= b)
            System.Console.WriteLine("Zero");
        else if(0 < a)
            System.Console.WriteLine("Positive");
        else if((Math.Min(b, -1) - a & 1) == 0)
            System.Console.WriteLine("Negative");
        else
            System.Console.WriteLine("Positive");

    }
    
    static void Main(string[] args)
    {
        new Program().slove();
    }
}


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

int main() {
  int N;
  cin >> N;
  
  bool flag = false;
  if(N % 10 == 7) flag = true;
  N = N /10;
  if(N % 10 == 7) flag = true;
  N = N /10;
  if(N % 10 == 7) flag = true;
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

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

int main(){
    ll n, m, d;
    cin >> n >> m >> d;

    double ans = ((double)(n-d))*2/(n*n)*(m-1);
  	if(d == 0) ans /= 2;

    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 3788
from collections import defaultdict

N, M = map(int, input().split())
X = list(map(int, input().split()))

R = [0 for _ in range(M)]
D = defaultdict(int)

for i in range(N):
    R[X[i] % M] += 1
    D[X[i]] += 1

P = [0 for _ in range(M)]

for k, v in D.items():
    P[k % M] += v // 2

res = R[0] // 2

for i in range(1, M // 2 + 1):
    if i * 2 == M:
        res += R[i] // 2
    else:
        x = min(R[i], R[-i])
        res += x
        res += min(P[i], (R[i] - x) // 2)
        res += min(P[-i], (R[-i] - x) // 2)

print(res)

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

using namespace std;

inline void Boost() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
typedef long long int ll;
typedef long double ld;

struct BipartiteMatcher {
    vector<vector<int>> G;
    vector<int> L, R, Viz;
 
    BipartiteMatcher(int n, int m) {
        G.resize(n);
        L.resize(n, -1);
        R.resize(m, -1);
        Viz.resize(n);
    }
 
    void AddEdge(int a, int b) {
        G[a].push_back(b);
    }
 
    bool Match(int node) {
        if(Viz[node]) 
            return false;
        Viz[node] = true;
     
        for(auto vec : G[node]) {
            if(R[vec] == -1 || Match(R[vec])) {
                L[node] = vec;
                R[vec] = node;
                return true;
            }
        }
 
        return false;
    }
    void Solve() {
        bool ok = true;
        while(ok) {
            ok = false;
            fill(Viz.begin(), Viz.end(), 0);
            for(int i = 0; i < L.size(); ++i)
                if(L[i] == -1)
                    ok |= Match(i);
        }
    }
};

int main() {
	Boost();

	int n;
	cin >> n;

	vector < pair < int, int > > A(n), B(n);
	for(auto &x: A) cin >> x.first >> x.second;
	for(auto &x: B) cin >> x.first >> x.second;

	BipartiteMatcher T(n, n);
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			if(A[i].first < B[j].first && A[i].second < B[j].second) {
				T.AddEdge(i, j);
			}
		}
	}
	T.Solve();

	int ans = 0;
	for(int i = 0; i < n; ++i) {
		if(T.L[i] != -1) {
			++ans;
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
    string S;
    cin>>S;
    int Q;
    cin>>Q;
    string R;
    int t,f;
    char c;
    bool b=false;
    for(int i=0;i<Q;i++){
        cin>>t;
        if(t==1){
            string tmp=S;
            S=R;
            R=tmp;
        }else{
            cin>>f>>c;
            if(f==1){
                R+=c;
            }else{
                S+=c;
            }
        }
    }
    reverse(R.begin(),R.end());
    string res=R+S;
    cout<<res;
  return 0;
}


Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
int dp[100001][3]={0};
int main(void){
	int n;
	int i,j,k;
	int a[100001][3];
	cin>>n;
	for(i=1;i<=n;i++){
		for(j=1;j<=3;j++){
			cin>>a[i][j];
		}
	}
	for(j=1;j<=3;j++){
		dp[1][j]=a[1][j];
	}
	for(i=1;i<n;i++){
		for(j=1;j<=3;j++){
			for(k=1;k<=3;k++){
				if(j==k)	continue;
				dp[i+1][k]=max(dp[i+1][k],dp[i][j]+a[i+1][k]);
			}
		}
	}
	/*  for(i=1;i<=n;i++){
		for(j=1;j<=3;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl; */
	int MAX=-1;
	for(j=1;j<=3;j++){
		MAX=max(MAX,dp[n][j]);
	}
	cout<<MAX<<endl;
	return 0;
}
		
	

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
//const ll p = 1e9 + 7;
//const ll p = 998244353;
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	ll n;
	cin >> n;
	vll a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];
	vll b(n + 1, 0);
	for (ll i = 0; i < n; i++) b[i + 1] = b[i] + a[i];

	ll ans = inf;

	ll x = 0, y = 0;
	for (ll i = 1; i <= n - 3; i++) {
		for (ll j = x; j < i; j++) {
			if (b[j + 1] >= b[i + 1] - b[j + 1]) {
				if (j == 0) x = j;
				else if (2 * b[j + 1] - b[i + 1] < b[i + 1] - 2 * b[j]) x = j;
				else x = j - 1;
				break;
			}
			if (j == i - 1) x = j;
		}
		y = max(y, i + 1);
		for (ll j = y; j < n - 1; j++) {
			if (b[j + 1] - b[i + 1] >= b[n] - b[j + 1]) {
				if (j == i + 1) y = j;
				else if (2 * b[j + 1] - b[i + 1] - b[n] < b[i + 1] + b[n] - 2 * b[j]) y = j;
				else y = j - 1;
				break;
			}
			if (j == n - 2) y = j;
		}
		ll p = b[x + 1], q = b[i + 1] - p, r = b[y + 1] - p - q, s = b[n] - p - q - r;
		ll z = max({p, q, r, s}) - min({p, q, r, s});
		//cout << endl;
		//cout << x << " " << i << " " << y << endl;
		//cout << p << " " << q << " " << r << " " << s << endl;
		//cout << z << endl << endl;
		ans = min(ans, z);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3328
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
def main():
    lis=[I(),I(),I(),I(),I()]
    dig1=[i%10 if i%10!=0 else 10 for i in lis]
    sum=0
    while len(lis)!=0:
        nex=0
        ind=0
        for i in range(len(lis)):
            if dig1[i]>nex:
                nex=dig1[i]
                ind=i
        
        #print(sum,lis[ind],10-nex)
        if len(lis)!=1:
            sum+=lis.pop(ind)+(10-nex)%10
            dig1.pop(ind)
        else:
            sum+=lis.pop()
    
    print(sum)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 9228
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int H, W, K;
  string s[300];
  int ans[300][300] = {};

  cin >> H >> W >> K;

  for (int i=0; i<H; i++)
    cin >> s[i];

  int id = 1;
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (s[i][j] == '#')
        ans[i][j] = id++;
    }
  }

  for (int i=0; i<H; i++) {
    for (int j=1; j<W; j++) {
      if (ans[i][j] == 0) {
        ans[i][j] = ans[i][j-1];
      }
    }
  }

  for (int i=0; i<H; i++) {
    for (int j=W-2; j>=0; j--) {
      if (ans[i][j] == 0) {
        ans[i][j] = ans[i][j+1];
      }
    }
  }

  for (int i=1; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (ans[i][j] == 0) {
        ans[i][j] = ans[i-1][j];
      }
    }
  }

  for (int i=H-2; i>=0; i--) {
    for (int j=0; j<W; j++) {
      if (ans[i][j] == 0) {
        ans[i][j] = ans[i+1][j];
      }
    }
  }

  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      printf("%d%c", ans[i][j], " \n"[j==W-1]);
    }
  }

  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string S;

int b[500005], c[500005];

int INF = 555555;

int ans[500005];

int main(void) {

	cin >> S;
	int N = S.size() + 1;
	S = ">" + S + "<";

	//cout << N << endl;

	//cout << S << endl;

	for (int i = 0; i <= N + 1; i++) { b[i] = -INF; c[i] = -INF; }

	for (int i = 0; i <= N+1; i++) {
		if (S[i] == '>' && S[i + 1] == '<') { b[i+1] = 0; c[i+1] = 0; }
	}

	for (int i = 0; i <= N; i++) {
		if (S[i] == '<') { b[i+1] = max(b[i+1], b[i] + 1); }
	}

	for (int i = N; i >= 0; i--) {
		if (S[i] == '>') { c[i] = max(c[i], c[i+1] + 1); }
	}

	for (int i = 1; i <= N; i++) {
		ans[i] = max(b[i], c[i]);
	}

	long long int val = 0;

	for (int i = 1; i <= N; i++) {
		val += ans[i];
	}

	cout << val << endl;

	/*for (int i = 0; i <= N + 1; i++) {
		cout << "b[" << i << "]= " << b[i] << endl;
	}*/

	return 0;
}

Measured memory_bytes: 6680
#include<bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
  int A,B;cin>>A>>B;
  for(int i=0;i<1010;i++){
    if((int)(i*1.08)==i+A&&(int)(i*1.1)==i+B){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i=0; i<n; ++i)
        cin >> p[i];

    int ans = 0;
    for(int i=1; i<n-1; ++i){
        if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1]))
            ++ ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
void main()
{
    long n = rdElem;

    long p = 1;
    foreach (i; 1 .. n+1)
    {
        p = p * i % mod;
    }

    p.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

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

int n;
double x[101], y[101], z[101], r[101], res;
struct Edge { int u, v; double cost; } tmp;
vector<Edge> edge;

bool comp(const Edge &e1, const Edge &e2)
{
    return e1.cost < e2.cost;
}

double sq(double x) { return x * x; }
double dis(int i, int j)
{
    return max(0.0, sqrt(sq(x[i] - x[j]) + sq(y[i] - y[j]) + sq(z[i] - z[j])) - r[i] - r[j]);
}

class UnionFind
{
private:
	int par[101];
	int rank[101];

public:
	void Init(int n)
	{
		for(int i = 0; i < n; ++i)
			par[i] = i, rank[i] = 0;
	}
	int Find(int x)
	{
		if(par[x] == x) return x;
		else return Find(par[x]);
	}
	void Unite(int x, int y)
	{
		x = Find(x); y = Find(y);
		if(x == y) return;
		if(rank[x] < rank[y]) par[x] = y;
		else par[y] = x;
		if(rank[x] == rank[y]) ++rank[x];
	}
	bool Same(int x, int y)
	{
		return Find(x) == Find(y);
	}
} uft;

int main()
{
    while(cin >> n && n)
    {
		res = 0.0;
		uft.Init(n);
        edge.clear();
        for(int i = 0; i < n; ++i)
            cin >> x[i] >> y[i] >> z[i] >> r[i];
        for(int i = 0; i < n; ++i)
        {
            for(int j = i + 1; j < n; ++j)
            {
                tmp.u = i, tmp.v = j;
                tmp.cost = dis(i, j);
                edge.push_back(tmp);
            }
        }
		sort(edge.begin(), edge.end(), comp);
		for(int i = 0, c = 0; c < n - 1; ++i)
		{
			tmp = edge[i];
			if(!uft.Same(tmp.u, tmp.v))
			{
				uft.Unite(tmp.u, tmp.v);
				res += tmp.cost;
				++c;
			}
		}
		printf("%.3f\n", res);
    }
}

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

using namespace std;


int dv(int k) {
  int a = 0;
  for (int i = 1; i <= k; ++i) {
    a += k%i==0;
  }
  return a==8;
}

int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    ans += dv(i) && i%2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
    static void Main(string[] args){
    var vals = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
    int N=vals[0];
    int X=vals[1];
    int cnt=1;
    int d=0;
    var L = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
    for(int i=0;i<N;i++){
        d+=L[i];
        if(d>X)break;
        cnt++;     
    }
    Console.WriteLine(cnt);
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <map>
#include <algorithm>
#include <functional>
#include <sstream>

using namespace std;

int l;

string exchange(const string s)
{
    int a, b;
    string a_s, b_s;
    stringstream s1, s2, ret;
    
    a_s = b_s = s;
    
    sort(a_s.begin(), a_s.end());
    sort(b_s.begin(), b_s.end(), greater<char>());
    s1 << a_s;
    s2 << b_s;

    s1 >> a;
    s2 >> b;
    a = b - a;
    ret << a;

    return ret.str();
}

int main()
{
    string s;

    while (cin >> s >> l, s != "0" || l) {
        map<string, int> m;

        while (s.size() < l)
            s = '0' + s;
        m[s] = 0;

        for (int i = 1; ; i++) {
            s = exchange(s);

            string tmp = s;
            while (tmp.size() < l)
                tmp = '0' + tmp;

            if (m.count(tmp) != 0) {
                cout << m[tmp] << " " << s << " " << i - m[tmp] << endl;
                break;
            }
            else
                m[tmp] = i;
            s = tmp;
        }
    }

    return 0;
}

Measured memory_bytes: 1268
def dif(s, l):
    diff = 0
    for i, j in zip(s, l):
        if i != j:
            diff += 1
    return diff


S = list(input())
S = list(map(int, S))
L1 = [int(1) if i % 2 == 0 else int(0) for i in range(len(S))]
L2 = [int(0) if i % 2 == 0 else int(1) for i in range(len(S))]
print(min(dif(S, L1), dif(S, L2)))


Measured memory_bytes: 5404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    int N, M, X; cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    for (int i = 0; i < N; i++) {
        scanf("%d", &C[i]);
        for (int j = 0; j < M; j++) {
            scanf("%d", &A[i][j]);
        }
    }

    int ans = 10000000;
    for (int tmp = 0; tmp < (1 << 12); tmp++) {
        bitset<12> s(tmp);
        int sum = 0;
        vector<int> Alg(M);
        for (int i = 0; i < N; i++) {
            if (s.test(i)) {
                sum += C[i];
                for (int j = 0; j < M; j++) {
                    Alg[j] += A[i][j];
                }
            }
        }

        bool flag = true;
        for (int i = 0; i < M; i++) {
            if (Alg[i] < X) flag = false;
        }
        if (flag) {
            chmin(ans, sum);
        }
    }

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

Measured memory_bytes: 3696
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

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

  int n;
  cin >> n;
  
  if(n % 2 == 0) cout << n << endl;
  else cout << n*2 << endl;

  return 0;
}

Measured memory_bytes: 256
H,W=map(int,input().split())

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(1,H+1):
    a=list(map(str,input().split()))
    for j in range(W):
        if a[j]=="snuke":
            print(A[j]+str(i))
            exit()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	long double a,b;
	cin>>a >> b;
	long double h, m;
	cin >> h>> m;
	long double HoursDegrees = (h/12.0) * 360.0;
	long double MinutesDegrees = m*6.0;
	HoursDegrees += MinutesDegrees/12.0;
	long double difference = HoursDegrees - MinutesDegrees;
	if(difference > 180){
		difference = abs(difference -360.00000);
	}
	cout << setprecision(15);
	difference = difference * (3.14159265358979323846/180.0);
	long double answer = ((a * a) + (b * b)) - (2.0*(a*b)*(cos(difference)));
	answer = sqrtl(answer);
	cout << answer;

}

Measured memory_bytes: 4180
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    string T = "CODEFESTIVAL2016";
    int ans = 0;
    rep(i, 16) {
        if (S[i] != T[i]) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
num_knight = int(input())

monsters = [int(x) for x in input().split(' ')]
knights = [int(x) for x in input().split(' ')]

initial_num_monster = sum(monsters)

for pos, power in enumerate(knights):
    if monsters[pos] <= power:
        defeated = monsters[pos]
        monsters[pos] = 0
        rest_power = power - defeated
    else:
        monsters[pos] -= power
        continue

    monsters[pos+1] = max(monsters[pos+1] - rest_power, 0)

rest_monster = sum(monsters)
print(initial_num_monster - rest_monster)
exit(0)


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

int main(){
	int N;
	cin >> N;
	
	int a[N],b[N],c[N-1];
	for(int i=0;i<N;i++){cin >> a[i];}
	for(int i=0;i<N;i++){cin >> b[i];}
	for(int i=0;i<N-1;i++){cin >> c[i];}
	
	int manzoku = 0;
	
	for(int i=0;i<N;i++){
		manzoku += b[a[i]-1];
		if(i>0 && a[i] == a[i-1]+1){
			manzoku += c[a[i-1]-1];
		}
	}	
	
	cout << manzoku << endl;
	return 0;		
			
}

Measured memory_bytes: 256
#include<stdio.h>
char dice[8][5][5];
int i,j,res,flag1,flag2;
int MIN(int x,int y){ return x<y?x:y; }
int input()
{
    for(i=1;i<=6;i++)
    {
        for(j=2;j>=0;j--)
        {
            scanf("%s",dice[i][j]);
            if(i==1&&j==2&&dice[i][j][0]=='#') return 0;
        }
    }
    return 1;
}
void f1(int a,int b)
{
    for(flag1=i=0;i<3;i++) if(dice[a][b][i]=='*') flag1=1;
}
void f2(int a,int b)
{
    for(flag2=i=0;i<3;i++) if(dice[a][b][i]=='*') flag2=1;
}
void f3(int a,int b)
{
    for(flag1=i=0;i<3;i++) if(dice[a][i][b]=='*') flag1=1;
}
void f4(int a,int b)
{
    for(flag2=i=0;i<3;i++) if(dice[a][i][b]=='*') flag2=1;
}
void C(int x)
{
    if(flag1&&flag2) res=MIN(res,x);
}
int main()
{
    while(input())
    {
        res=10000;

        f1(1,0),f2(3,0),C(0);
        f1(1,2),f2(3,2),C(2);
        f3(1,0),f4(3,2),C(1);
        f3(1,2),f4(3,0),C(1);

        f1(2,0),f2(4,0),C(3);
        f1(2,2),f2(4,2),C(3);
        f3(2,0),f4(4,2),C(2);
        f3(2,2),f4(4,0),C(2);

        for(flag1=i=0;i<3;i++) if(dice[5][0][i]=='*') flag1=1;
        for(flag2=i=0;i<3;i++) if(dice[6][2][i]=='*') flag2=1;
        C(1);
        for(flag1=i=0;i<3;i++) if(dice[5][2][i]=='*') flag1=1;
        for(flag2=i=0;i<3;i++) if(dice[6][0][i]=='*') flag2=1;
        C(1);
        for(flag1=i=0;i<3;i++) if(dice[5][i][0]=='*') flag1=1;
        for(flag2=i=0;i<3;i++) if(dice[6][2-i][0]=='*') flag2=1;
        C(2);
        for(flag1=i=0;i<3;i++) if(dice[5][i][2]=='*') flag1=1;
        for(flag2=i=0;i<3;i++) if(dice[6][2-i][2]=='*') flag2=1;
        C(2);

        printf("%d\n",res);
    }
    return 0;
}

Measured memory_bytes: 536
require 'prime'

def modpow x, n, m
    r=1
    while n>0
        r=r*x%m if n.odd?
        x=x*x%m
        n/=2
    end
    r
end

N, M=gets.split.map &:to_i
MOD=10**9+7
MAX=N+1000

t=1
fact=[1]+(1..MAX).map{|i| t*=i; t%=MOD}
inv=[modpow(fact[MAX], MOD-2, MOD)]*(MAX+1)
MAX.downto(1){|i| inv[i-1]=inv[i]*i%MOD}

comb=->n, r{ n<r ? 0 : fact[n]*inv[n-r]*inv[r]%MOD}

res=1
M.prime_division.each{|_, k| res=res*comb[N+k-1, k]%MOD}
puts res


Measured memory_bytes: 4408
n=int(input())
a=list(map(int,input().split()))
b=[]
count=0
countt=0
for i in a:
  if i%2==0:
    b.append(i)
    count+=1
for j in b:
  if j%3==0 or j%5==0:
    countt+=1
if count==countt:
  print("APPROVED")
else:
  print("DENIED")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int n;
long long l,a[100007],vis[100007];
vector <int> ans;
void no(){
	cout<<"Impossible";
	exit(0);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n>>l;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<n;i++){
		if(a[i]+a[i+1]>=l){
			ans.push_back(i);
			break;
		}
	}
	if(ans.empty()) no();
	cout<<"Possible\n";
	for(int i=1;i<ans[0];i++) cout<<i<<" ";
	for(int i=n-1;i>=ans[0]+1;i--) cout<<i<<" ";
	cout<<ans[0];
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a[60];
	cin>>n;
	int ma=0, idx=0;
	REP(i, n){
		cin>>a[i];
		if(ma<abs(a[i])){
			ma=abs(a[i]);
			idx=i;
		}
	}
	cout<<2*n-1<<'\n';
	REP(i, n){
		cout<<idx+1<<' '<<i+1<<'\n';
	}
	if(a[idx]>0){
		REP(i, n-1){
			cout<<i+1<<' '<<i+2<<'\n';
		}
	}
	else{
		FORR(i, 0, n-1){
			cout<<i+2<<' '<<i+1<<'\n';
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define peintD(a) cout << setprecision(10) << ans << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n,m;

signed main(){
    REP(i,9){
        REP(j,9){
            cout << i+1 << "x" << j+1 << "=" << (i+1)*(j+1) << endl;
        }
    }
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}



Measured memory_bytes: 2920
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>
#include<iterator>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;

bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}

lli check(vector<lli>& vec, lli n,lli cmp, lli num) {
	if (num > 26)return -1;
	if (vec[n] == cmp)return 1;
	else return check(vec, vec[n], cmp, num + 1);
}

int main() {
	string s;
	cin >> s;
	lli n,num=0;
	cin >> n;

	while (s[num] == '1')num++;
	if (num >= n)cout << '1';
	else cout << s[num];

}


Measured memory_bytes: 256
A, B = map(int, input().split())

cnt = 0
for i in range (A, B+1):
    a = (i // 10000) % 10 #5桁目
    b = (i // 1000) % 10 #4桁目
    c = (i // 10) % 10 #2桁目
    d = i % 10 #1桁目
    if a == d and b == c:
        cnt += 1

print(cnt)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 Scanner sc= new Scanner(System.in);
		 int A = sc.nextInt();
		 int B = sc.nextInt();
		 int C = sc.nextInt();
		 int D = sc.nextInt();
		 int Train = 0;
		 int Bus = 0;
		 if(A>B) {
			 Train = Train + B;
		 }
		 else {
			 Train = Train + A;
		 }
		 if(C>D) {
			 Bus = Bus + D;
		 }
		 else {
			 Bus = Bus + C;
		 }
		 System.out.println(Train+Bus);
	}

}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define rep(i, n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) cout << setfill('0') << setw(len) << right << a << endl;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

signed main() {
    int n;
    cin >> n;
    vi p = vi(n);
    rep(i, n) cin >> p[i];

    sort(ALL(p));
    int ans = accumulate(p.begin(), p.end(), 0);
    ans -= p[p.size() - 1] / 2;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define ll long long
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define abs(a,b) (a-b>0?a-b:b-a)


int main(){
    int n;
    cin >> n;
    vi a(n);
    int ans=0;
    rp(i,n){
        cin >> a.at(i);
        ans+=a.at(i)-1;
    }
    cout << ans << endl;
}








Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;


public class Main {

	/**
	 * @param args
	 */
	
	
	public static void main(String[] args) {
		
		
		
		Scanner sc= new Scanner(System.in);
	
	
		long n=sc.nextLong();
		long m=sc.nextLong();
		
		long ans=0;
		
		if(2*n<=m)
		{
			ans+=n;
			m-=2*n;
		    ans+=m/4;		
		}
		else 
		{
		if(m%2!=0)	
		{
		ans=(m-1)/2;	
		}
		else 
		{
		ans=m/2;	
		}
		}
	System.out.println(ans);	
			
}
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    int x[100001], diff[100001];
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> x[i];
    }
    
    sort(x, x + m);
    
    if (n == 1) {
        cout << x[m - 1] - x[0] << '\n';
        return 0;
    }
    
    if (n >= m) {
        cout << 0 << '\n';
        return 0;
    }
    
    priority_queue<int, vector<int>, greater<int>> pq;
    for (int i = 0; i < m - 1; i++) {
        diff[i] = x[i + 1] - x[i];
        pq.push(diff[i]);
        if (pq.size() > n - 1) pq.pop();
    }
    
    int diff_sum = 0;
    while (!pq.empty()) {
        diff_sum += pq.top();
        pq.pop();
    }
    
    cout << (x[m - 1] - x[0]) - diff_sum << '\n';
    
    return 0;
}


Measured memory_bytes: 1532
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define M_PI 3.14159265358979323846
// #define __LOCAL

#ifdef __LOCAL
#define DBG(X) cout << #X << " = " << (X) << endl;
#define SAY(X) cout << (X) << endl;
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

int n,m,x;
vector<int> V,W;

int main()
{
    fast_io();
    n = fetch<int>();
    V = fetch_vec<int>(n);
    DBG(n);
    DBG(V);
    int count=1;
    for(int i=0;i<n;i++){
        if(V[i]==count) count++;
    }
    count--;
    int ans = n-count;
    
    if(ans==n)
        cout << "-1" << endl;
    else
        cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
const int N = 2*(int)1e5 + 10;

int n, a[N];
int dp[N], dp_on_num[N];

int32_t main(){_

   cin>>n;

   vector<int> v;
   v.emplace_back(0);
   for (int i = 1; i <= n; ++i)
   {
      int x;
      cin>>x;
      if(v.back() == x)continue;
      v.emplace_back(x);
   }

   n = sz(v);
   dp[0] = 1;

   for (int i = 1; i < n; ++i)
   {
      dp[i] = dp[i-1];
      dp[i] += dp_on_num[v[i]];
      dp[i] %= mod;
      dp_on_num[v[i]] = dp[i];
   }
   
   cout<<dp[n-1];
   #warning make sure N size is correct!
   return 0;
}

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

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

int gcd(int a, int b) {
	return !b ? a : gcd(b, a % b);
}

bool win(const vector<int> &v) {
	int evens = 0;
	for(auto &each : v) {
		evens += each % 2 == 0;
	}
	if(evens & 1) {
		return true;
	}
	else if((int) v.size() - evens == 1) {
		vector<int> next_v = v;
		int gc = 0;
		for(auto &each : next_v) {
			if(each & 1) {
				if(each == 1) {
					return false;
				}
				each--;
			}
			gc = gcd(gc, each);
		}
		for(auto &each : next_v) {
			each /= gc;
		}
		return !win(next_v);
	}
	return false;
}

int main() {
	ios_base::sync_with_stdio(false);

	int n;
	cin >> n;
	vector<int> v(n);
	fori(i, 0, n) {
		cin >> v[i];
	}
	
	cout << (win(v) ? "First" : "Second") << '\n';

	return 0;
}



Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t A,B,n,m,k,j,ans=0;
  cin >> n >> m >> k;
  int64_t a[n+1],b[m+1];
  a[0]=0,b[0]=0;
  for(int64_t i=1;i<=n;i++){
    cin >> a[i];
    a[i]+=a[i-1];
  }
  for(int64_t i=1;i<=m;i++){
    cin >> b[i];
    b[i]+=b[i-1];
  }
  j=m;
  for(int i=0;i<=n;i++){
    if(k<a[i])break;
    while(b[j]>k-a[i])j--;
    ans=max(ans,i+j);
  }
  cout << ans << endl;
}
    
    

Measured memory_bytes: 6752
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
D1 = defaultdict(int)
D2 = defaultdict(int)

for i in range(0,N,2):
  D1[A[i]]+=1
for i in range(1,N,2):
  D2[A[i]]+=1
  
D1_sorted = sorted(D1.items(), key=lambda x:x[1], reverse = True) + [(-1,0)]
D2_sorted = sorted(D2.items(), key=lambda x:x[1], reverse = True) + [(-1,0)]
i, j = 0, 0
while i < len(D1_sorted) -1 and j < len(D2_sorted) -1:
  if D1_sorted[i][0] != D2_sorted[j][0]:
    break
  elif D1_sorted[i][1] > D2_sorted[j][1]:
    j+=1
  elif D1_sorted[i][1] < D2_sorted[j][1]:
    i+=1
  else:
    if D1_sorted[i+1][1] > D2_sorted[j+1][1]:
      i+=1
    else:
      j+=1

print(N-D1_sorted[i][1]-D2_sorted[j][1])

Measured memory_bytes: 27024
/* ex7_3
    suuxxu */

#include <stdio.h>
#include <stdbool.h>

int main(void){
    int height, width, i, j;
    bool memo_col[100] = {}; // 行が黒マスを含むか
    bool memo_row[100] = {}; // 列が黒マスを含むか
    char **square;

    // heightとwidthにH, Wを入力
    scanf("%d %d", &height, &width);

    // int型配列squareのメモリを動的確保
    square = (char**)calloc(height, sizeof(char*));
    if(square == NULL){
        fprintf(stderr, "memory allocation error.¥n"); exit(1);
    }
    for(i = 0; i < height; i++){
        square[i] = (char*)calloc(width, sizeof(char));
        if(square[i] == NULL){
            fprintf(stderr, "memory allocation error.¥n");
            exit(1);
        }
    }

    // squareにa_{i,j}を入力
    for (i = 0; i < height; i++){
        for (j = 0; j < width; j++){
            scanf(" %c", &square[i][j]);
        }
    }

    // squareの各要素が黒マスであるか確認
    for (i = 0; i < height; i++){
        for (j = 0; j < width; j++){
            if (square[i][j] == '#'){
                memo_col[i] = true; // その行は黒マスを含む
                memo_row[j] = true; // その列は黒マスを含む
            }
        }
    }

    // 結果を出力
    for (i = 0; i < height; i++){
        if(memo_col[i] == true){ // 黒マスを含むなら出力
            for (j = 0; j < width; j++){
                if(memo_row[j] == true){ // 黒マスを含むなら出力
                    printf("%c", square[i][j]);
                }
            }
        printf("\n");
        }
    }

    // メモリ解放
    for(i = 0; i < height; i++){
        free(square[i]);
    }
    free(square);

    return 0;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  ll H, N;
  cin >> H >> N;
  vector<ll> A(N);
  vector<ll> B(N);

  vector<ll> dp(H+1, 1000000000000);
  dp[0] = 0;

  for(int i = 0; i < N; i++){
    cin >> A.at(i) >> B.at(i);
    dp[A.at(i)] = min(dp[A.at(i)], B.at(i));
  }

  for(int i = 0; i <= H-1; i++){
    for(int j = 0; j < N; j++){
      if(i+A[j] <= H){
        dp[i + A[j]] = min(dp[i+A[j]], dp[i] + B[j]); 
      }
      if(i+A[j] >= H){
        dp[H] = min(dp[H], dp[i] + B[j]); 
      }
    }
  }
  cout << dp[H] << endl;





}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    string s,t;cin>>s>>t;
    ll res=0;
    rep(i,s.size()){
        if(s[i]!=t[i])res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3920
#include<bits/stdc++.h>
using namespace std;
vector<int> v[1<<17];int n,k,a,y,i=1;
int s(int x,int p=0){int r=0;for(int to:v[x])r=max(r,s(to,x));if(++r>=k&&p)a++,r=0;return r;}
int main(){cin>>n>>k>>y;if(y!=1)a++;while(i<n){cin>>y;v[y-1].push_back(i++);}s(0);cout<<a;}

Measured memory_bytes: 11136
n, yen = map(int, input().split())
ans = [-2, -2, 2]
for i in range(n + 1):
    if(ans[0] != -2):
            break
    for j in range(n + 1):
        if(i + j > n):
            continue
        x = i
        y = j
        z = n - x - y
        if(yen - 10000 * x - 5000 * y - 1000 * z  == 0):
            ans[0] = x
            ans[1] = y
            ans[2] = z
            break
if(ans[0] == -2):
    print("-1 -1 -1")
else:
    print("{} {} {}".format(ans[0], ans[1], ans[2]))                            


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

using namespace std;

int main()
{
    list<char> word;
    char c;
    while ((c = getchar()) != '\n')
    {
        word.push_back(c);
    }
    for (list<char>::iterator it = word.begin(); it != word.end(); it++)
        putchar(*it);
    if (word.back() == 's') putchar('e');
    putchar('s');
    return 0;
}


Measured memory_bytes: 3636
n,k = map(int, input().split())
mod = 10**9+7 
N = 2000 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
for i in range(k):
  print(cmb(k-1, i)*cmb(n-k+1,i+1)%mod)

Measured memory_bytes: 9324
import numpy as np

N = raw_input().split(" ")
N = map(int,N)

ref = [2,3,4,5,6,7,8,9,10,11,12,13,1]

a = ref.index(N[0])
b = ref.index(N[1])

if a<b:
    print "Bob"
elif a==b:
    print "Draw"
else:
    print "Alice"

Measured memory_bytes: 12828
using System;
using System.Linq;

namespace ABC072D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] p = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

            bool[] pb = new bool[n];
            for (int i = 0; i < n; i++)
            {
                pb[i] = p[i] == i + 1;
            }

            bool before = false;
            int count = 0;
            for (int i = 0; i < n; i++)
            {
                if (pb[i] & !before)
                {
                    count++;
                    before = true;
                }
                else if (pb[i] & before)
                {
                    before = false;
                }
                else
                {
                    before = false;
                }
            }

            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 20192
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

int main(int argc, char const *argv[])
{
    double r,pi;
    cin >> r;
    pi = M_PI;
    cout << fixed << setprecision(6) << (pi * r * r) << " " << (2 * pi * r) << endl;
    return 0;
}


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


public class Main {
	public static void main(String[] args){
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			int n = scan.nextInt();
			for(int i = 0 ; i < n;i++){
				char[] data = scan.next().toCharArray();
				int[] num = new int[data.length];
				for(int j = 0 ; j < data.length;j++){
					num[j] = Integer.parseInt(String.valueOf(data[j]));
				}
				Arrays.sort(num);
				int ans = 0;
				for(int j = 0 ;j < num.length;j++){
					ans += num[j] * Math.pow(10, j);
					ans -= num[j] * Math.pow(10, 7 -j);
				}
				System.out.println(ans);
			}
		}finally{
			if(scan !=null)scan.close();
		}
	}
}

Measured memory_bytes: 17192
N = int(input())
A = list(map(int, input().split()))

sep = N//2
for i in range(N):
  if sum(A[:sep]) >= sum(A[sep:]):
    sep -= N//((i+2)**2)
  else:
    sep += N//((i+2)**2)
  if N//((i+2)**2) == 1:
    break
#print(sep)


a = abs(sum(A[:sep])-sum(A[sep:]))
b = abs(sum(A[:sep+1])-sum(A[sep+1:]))
c = abs(sum(A[:sep-1])-sum(A[sep-1:]))
d = abs(sum(A[:sep+2])-sum(A[sep+2:]))
e = abs(sum(A[:sep-2])-sum(A[sep-2:]))
print(min(a,b,c,d,e))

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

const int nm = 200;
int n;
bool g[nm][nm];
int c[nm], d[nm][nm];

bool bi(int v) {
	for (int i = 0; i < n; i++)
		if (g[v][i])
			if (c[i]) {
				if (c[i] == c[v])
					return 0;
			} else {
				c[i] = c[v] * -1;
				if (!bi(i))
					return 0;
			}
	return 1;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < n; j++) {
			g[i][j] = s[j] - '0';
			if (g[i][j])
				d[i][j] = 1;
			else if (j != i)
				d[i][j] = nm;
		}

	}

	c[0] = 1;
	if (!bi(0)) {
		cout << -1 << endl;
		return 0;
	}

	for (int k = 0; k < n; k++)
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

	int m = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			m = max(m, d[i][j]);
	cout << m + 1 << endl;
}


Measured memory_bytes: 384