akhauriyash/Code-Regression huggingface dataset:
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
6 1
3
---+/
/+---test
10 2
4
5
---+/
/+---test
100 5
1
23
45
67
89
---+/

enum MOD = 1000000007;

void main(string[] args) {
  long N, M;
  readf(" %d %d ", &N, &M);

  auto A = new bool[](N);
  foreach (i; 0..M) {
    const a = readln.chomp.to!long;
    A[a] = true;
  }

  auto dp = new long[N+1];
  dp[0..2] = 1;
  foreach (i; 2..N+1) {
    if (!A[i-1]) dp[i] = (dp[i] + dp[i-1])%MOD;
    if (!A[i-2]) dp[i] = (dp[i] + dp[i-2])%MOD;
  }
  dp[$-1].writeln;
}


Measured memory_bytes: 3708
import heapq
class Dijkstra:
    INF = 10**18
    threshold = 10**9

    def __init__(self, N):
        self.MAX_V = N + 1
        self.dist = [self.INF] * self.MAX_V
        self.G = [[] for _ in range(self.MAX_V)]

    def insert(self, X, Y, cost): self.G[X].append((cost * self.threshold + Y, 0))

    def dijkstra(self, st):
        q = []
        heapq.heappush(q, (st, 0))
        self.dist[st] = 0

        while len(q):
            p = heapq.heappop(q)[0]
            cost = p // self.threshold
            node = p - cost * self.threshold
            if cost > self.dist[node]: continue
            for to in self.G[node]:
                to_cost = to[0] // self.threshold
                to_node = to[0] - to_cost * self.threshold
                to_cost += self.dist[node]
                if self.dist[to_node] > to_cost:
                    self.dist[to_node] = to_cost
                    heapq.heappush(q, (to_cost * self.threshold + to_node, 0))

h, w = map(int, input().split())
sh, sw = map(int, input().split())
eh, ew = map(int, input().split())

sh -= 1
sw -= 1
eh -= 1
ew -= 1

S = [input() for _ in range(h)]

di = Dijkstra(h*w)
for x in range(h):
    for y in range(w):
        if S[x][y] == '#': continue
        for i in range(-2, 3):
            for j in range(-2, 3):
                X = x + i
                Y = y + j
                if X < 0 or Y < 0 or X >= h or Y >= w or S[X][Y] == '#': continue
                D = abs(i) + abs(j)

                if D == 1: di.insert(x * w + y, X * w + Y, 0)
                if D >= 2: di.insert(x * w + y, X * w + Y, 1)

di.dijkstra(sh * w + sw)
ans = di.dist[eh * w + ew]
if ans == 10**18: print(-1)
else: print(ans)


Measured memory_bytes: 358504
S = input()
N = len(S)
flag = True
for i in range(N//2):
    if S[i]!=S[N-1-i]:
        flag = False
moji1 = S[:((N-1)//2)]
for i in range(N//2):
    if moji1[i]!=moji1[len(moji1)-1-i]:
        flag = False
moji = S[((N+3)//2)-1:]
for i in range(N//2):
    if moji[i]!=moji[len(moji)-1-i]:
        flag = False

print("Yes" if flag==True else "No")

Measured memory_bytes: 38384
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
const int M=3e5+10;
int A[M],P[M],n,ans;
const char Ans[2][23]={"No\n","Yes\n"};
struct Array{
	int num[M];
	int top;
	void clear(){top=0;}
	void insert(int a){num[++top]=a;}
	int &operator [](int a){return num[a];}
	int size(){return top;}
}s1,s2;

bool calc(int l,int r){
	s1.clear();s2.clear();
	for(int i=l+1;i<=r;i+=2) if(A[i]!=i) return 0;
	for(int i=l;i<=r;i+=2){
		if(A[i]<=i) s2.insert(A[i]);
		else s1.insert(A[i]);
	}
	for(int i=1,up=s1.size();i<up;i++){
		if(s1[i]>s1[i+1]) return 0;
	}
	for(int i=1,up=s2.size();i<up;i++){
		if(s2[i]>s2[i+1]) return 0;
	}
	return 1;
}

void work(){
	ans=1;
	int okl=1,okr=1;
	for(int i=1;i<=n;){
		for(;i<=n;i++){
			if(P[i]>okr) okr=P[i];
			if(i==okr) break;
		}
		if(!calc(okl,okr)){
			ans=0;break;
		}
		i=okl=okr+1;
		++okr;
	}
	printf("%s",Ans[ans]);
}

void readIn(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&A[i]);
		P[A[i]]=i;
	}
}

int main(){
	readIn();
	work();
	return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <algorithm>
int N;
int K;

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


Measured memory_bytes: 256
#include <stdio.h>

#define MAX(x, y) ((x) > (y) ? (x) : (y))

int main(void)
{
	char game[3][256];
	int score[2];
	
	while (1){
		for (int i = 0; i < 3; i++){
			scanf("%s", game[i]);
			if (game[0][0] == '0') return (0);
		}
		
		for (int i = 0; i < 3; i++){
			score[0] = score[1] = 0;
			for (int j = 1; game[i][j] != '\0'; j++){
				if (game[i][j] == 'A'){
					score[0]++;
				}
				else {
					score[1]++;
				}
			}
			MAX(score[0], score[1])++;
			
			printf("%d %d\n", score[0], score[1]);
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
	long long n,i,j,k,ans;
	ans=0;
	string x;
	string s[1000];
	cin>>n;
	for (i=0;i<n;i++)
	{
		cin>>s[i]>>arr[i];
	}
	cin>>x;
	for (i=n-1;i>=0;i--)
	{
		if (s[i].compare(x)==0)
		{
			break;
		}
		else
		{
			ans=ans+arr[i];
		}
	}
	cout<<ans<<endl;
}

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

int main(){
  int N, x;
  cin >> N;
  for(int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    x += r - l + 1;
  }
  cout << x << endl;
  return 0;
} 

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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 (b < a) { a = b; return 1; } return 0; }



void func(long long A, long double B){

    cout<<(lli)(A*B)<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long A;
    scanf("%lld",&A);
    long double B;
    scanf("%Lf",&B);
    func(A, B);
    return 0;
}


Measured memory_bytes: 3836
N,W,H=gets.split.map(&:to_i)

hori = [0]*(W+1)
vert = [0]*(H+1)

N.times{
  x,y,w=gets.split.map(&:to_i)
  hori[[x-w,0].max] += 1
  hori[[x+w,W].min] -= 1
  vert[[y-w,0].max] += 1
  vert[[y+w,H].min] -= 1
}


t = 0
W.times{|i|
  hori[i] = ( t += hori[i] )
}
t = 0
H.times{|i|
  vert[i] = ( t += vert[i] )
}

puts (hori[0..-2].all?{|i|i>0}||vert[0..-2].all?{|i|i>0})?"Yes":"No"


Measured memory_bytes: 10472
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
     Scanner scan = new Scanner(System.in);
     int a = scan.nextInt();
     int b = scan.nextInt();
     
     if(a > b){
    	 System.out.println( "a > b" );
     }else if(a < b){
    	 System.out.println( "a < b" );
     }else{
    	 System.out.println( "a == b" );
     }
    }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

void solve() {
    int h, n;
    cin >> h >> n;
    int sum = 0;
    rep(i, n){
        int a;
        cin >> a;
        sum += a;
    }
    if (sum >= h) {
        cout << "Yes"<< endl;
    } else {
        cout << "No" << endl;
    }
    return;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N, M, a, b;
	cin >> N >> M;
	vector<vector<int>> jobs(M+1, vector<int>());
	rep(i,N){
		cin >> a >> b;
		if(a > M)continue;
		jobs[a].push_back(b);
	}
	priority_queue<int> Q;
	ll ans = 0;
	for(int i = 1; i <= M; ++i){
		for(auto x:jobs[i]){
			Q.push(x);
		}
		if(!Q.empty()){
			ans += Q.top();
			Q.pop();
		}
	}
	cout << ans << endl;
}


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

int main(void) {
  int i, j, k, h, w;
  char s[10];
  scanf("%d%d", &h, &w);
  for(i = 0; i < h; ++i) for(j = 0; j < w; ++j) {
    scanf("%s", s);
    if(!strcmp(s, "snuke")) printf("%c%d", j + 'A', i + 1);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,pair<int,int> >Piii;

int par[111111];
int rnk[111111];
int n,m;

int root(int a){
	return par[a]!=a?root(par[a]):a;
}

void unite(int a,int b){
	if(rnk[a]>rnk[b]) swap(a,b);
	par[root(a)] =  root(b);
	rnk[root(b)] += rnk[root(a)];
}

Piii v[100000];

int main(){
	for(int i=0;i<111111;i++)par[i]=i;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b,c;
		cin>>a>>b>>c;
		v[i]=make_pair(c,make_pair(a,b));
	}
	sort(v,v+m);

	int sum=0;

	for(int i=0;i<m;i++){
		int A=v[i].second.first;
		int B=v[i].second.second;
		if(root(A)==root(B)) continue;
		sum += v[i].first;
		unite(A,B);
	}

	cout<<sum<<endl;
}


Measured memory_bytes: 4728
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

map<string, int> counter;

int main(void) {
    int N;
    cin >> N;

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        ans += counter[s];
        counter[s]++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,m,tot,d[N],dp[N],head[N],nex[N],to[N];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int u,v;scanf("%d%d",&u,&v);
        add(u,v);d[v]++;
    }
    queue<int>q;
    for(int i=1;i<=n;i++)
        if(!d[i]) q.push(i);
    while(!q.empty())
    {
        int u=q.front();q.pop();
        for(int i=head[u];i;i=nex[i])
        {
            int v=to[i];
            dp[v]=max(dp[v],dp[u]+1);
            d[v]--;
            if(!d[v]) q.push(v);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
    printf("%d\n",ans);
}


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

int main() {
    string s;
    cin>>s;
    int k;
    cin>>k;
    vector<vector<int>> ind(26);
    for(int i = 0; i < s.size(); ++i) {
        ind[s[i]-'a'].push_back(i);
    }
    set<string> ss;
    for(int i = 0; i < 26; ++i) {
        int prev = -1;
        for(int j = 0; j < ind[i].size(); ++j) {
            int st = ind[i][j];
            string temp;
            //if(prev != -1 && s.substr(st, st + 5) == s.substr(prev, prev + 5))
            //    continue;
            for(int k = st; k < min((int)s.size(), st + 5); ++k) {
                temp.push_back(s[k]);
                ss.insert(temp);
            }
            prev = st;
        }
        if(ss.size() >= k) break;
    }
    for(auto i : ss) {
        k--;
        if(k == 0) {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}

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

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    if(c - a - b <= 0) {
        cout << "No" << endl;
    }
    else {
        ll x = (c - a - b) * (c - a - b);
        if(x > 4 * a * b) {
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision; // int64_tは9*10^18まで

int main() {
  int n;
  cin >> n;
  cout << n*(n+1)/2;
  return 0;
}

Measured memory_bytes: 3404
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

int intceil(int a, int b) {
    return (a + (b - 1)) / b;
}

signed main() {
    ll A, B, C;
    cin >> A >> B >> C;
    if (C - A - B < 0) {
        cout << "No" << endl;
    } else if ((C - A - B) * (C - A - B) > 4 * A * B) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int const N =1000+9;
int dp[N][N];
int main() {
    int n,m;
    cin>>n>>m;
    char arr[n+1][m+1];
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            cin>>arr[i][j];
        }
    }
    dp[0][1] = 1;
    for(int i =1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            if(arr[i][j] =='#')
                dp[i][j] = 0;
            else
                dp[i][j] = (dp[i][j-1] + dp[i-1][j])%mod;
        }
    }
    cout<<dp[n][m];
    return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 200005;
const int mod = 998244353;
vector<int>g[maxn];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<ll,ll>>v;
    f(n) {
        ll x, y;
        cin >> x >> y;
        v.pb({x,y});
    }
    reverse(all(v));
    ll ans = 0;
    for (auto &i : v) {
        ll cur = i.F + ans;
        if (cur != 0)
            cur = ((cur - 1) / i.S + 1) * i.S;
        ans = cur - i.F;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 7156
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL-1
double EPS=1e-9;
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef complex<double> P;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
set<int> nums;
int main(){
	int n,t;
	cin>>n>>t;
	vi a(n),b;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int ma=a[n-1];
	for(int i=n-1;i>=0;i--){
		if(ma<a[i])ma=a[i];
		b.pb(ma-a[i]);
	}
	sort(all(b));
	reverse(all(b));
	int hoge=b[0];
	int ans=0;
	//rep(i,n)cout<<b[i]<<endl;
	for(int i=0;i<n;i++){
		if(b[i]!=hoge)break;
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

#define inf  1000000007
#define ll long long
#define PA pair<int,int>
#define PPAP pair<int,PA>
#define  MP make_pair
#define  PB push_back

using namespace std;
long long  mod = 1000000007;

int main(){
	string s;
	cin >> s;
	if(s.size()>=4){
		if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I'){
			cout << "Yes" << endl;
			return 0;
		}
	}	
	cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
dam = list(map(int, input().split()))

mountains = [0] * N

x2 = 0
for i in range(N):
    if i % 2:
        x2 -= dam[i]
    else:
        x2 += dam[i]

mountains[0] = x2 // 2
for i in range(N-1):
    mountains[i+1] = dam[i] - mountains[i]

print(' '.join([str(x*2) for x in mountains]))



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

using namespace std;
using llint = long long;
using pint = pair<int,int>;

#define LOG(x) cout << "# " << #x <<" => "<< (x) <<endl

const int INF = 1<<28;
const llint LLINF = 1LL<<60;

int n, ans=0;
vector<int> d;

int main() {
    // Input
    cin >> n;
    d.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> d.at(i);
    }

    // Solve
    sort(d.begin(), d.end());
    for (int i = 1; i <= pow(10, 5); ++i) {
        int l = lower_bound(d.begin(), d.end(), i) - d.begin();
        if (l==n/2)
        {
            ans++;
        }
    }

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

Measured memory_bytes: 768
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[44][2][2];

int main(void){
	int i,j,k,n,p,q;
	ll x,y,s,z=0ll,a;
	std::fill(dp[0][0],dp[44][0],INFLL);
	std::cin >> n >> x >> y;
	for(i=2; i<n; ++i){
		std::cin >> a;
		z ^= a;
	}
	s = x+y;
	dp[43][0][0] = 0ll;
	for(i=42; i>=0; --i){
		for(j=0; j<2; ++j){
			for(k=0; k<2; ++k){
				for(p=0; p<2; ++p){
					for(q=0; q<2; ++q){
						if((((z>>i)&1)!=(p^q))){
							continue;
						}
						if(((s>>i)&1)+j*2-(p+q)>1 || ((s>>i)&1)+j*2<(p+q)){
							continue;
						}
						if(!(k || (((x>>i)&1)>=p))){
							continue;
						}
						dp[i][((s>>i)&1)+j*2-(p+q)][k|(((x>>i)&1)>p)] = std::min(dp[i][((s>>i)&1)+j*2-(p+q)][k|(((x>>i)&1)>p)],dp[i+1][j][k]+(1ll<<i)*(((x>>i)&1)-p));
					}
				}
			}
		}
	}
	a = std::min(dp[0][0][0],dp[0][0][1]);
	std::cout << ((a<x)?a:(-1ll)) << std::endl;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <cmath>

using namespace std;

int main() {
    size_t n;
    cin >> n;
    size_t c = 0;
    for (size_t i = 1; i <= n; ++i) {
        if (i % 2 == 1) {
            size_t d = 0;
            bool b = false;
            for (size_t j = 1; j <= n; ++j) {
                if (i % j == 0) {
                    if (++d == 8)
                        b = true;
                    else if (d > 8) {
                        b = false;
                        break;
                    }
                }
            }
            if (b)
                ++c;
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 500010
int n,q,a[N],cnt[N],bel[N],l,r,ans[N];
const int B=sqrt(N);
struct rua
{
	int l,r,id;
	void read(int i){scanf("%d%d",&l,&r),id=i;}
	bool operator <(const rua &t)const{return (bel[l]^bel[t.l])?bel[l]<bel[t.l]:((bel[l]&1)?r<t.r:r>t.r);}
}f[N];
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++)
	  f[i].read(i);
	for(int i=1;i<=q;i++)
	  bel[i]=i/B;
	sort(f+1,f+q+1);
	int l=1,r=0,cur=0;
	for(int i=1;i<=q;i++)
	  {
	  int ql=f[i].l,qr=f[i].r;
	  while(l<ql)cur-=!--cnt[a[l++]];
	  while(l>ql)cur+=!cnt[a[--l]]++;
	  while(r<qr)cur+=!cnt[a[++r]]++;
	  while(r>qr)cur-=!--cnt[a[r--]];
	  ans[f[i].id]=cur;
	  }
	for(int i=1;i<=q;i++)
	  printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 17372
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<time.h>
#include<cstdlib>
typedef long long ll;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mm(a) memset(a,0,sizeof(a))
#define lr rt<<1
#define rr rt<<1|1
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0);
#define inf 0x3f3f3f3f
#define eqs 1e-8
#define lb(x) (x&(-x))
#define ch(a) (int(a-'a')+1)
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef pair<int,int> pii;
const double pi=acos(-1);
const int maxn=100005;
//const ll Mod=1000000007;
using namespace std;

int n,L[maxn],R[maxn],id[maxn],zxr,pr,pl,zdl;

bool cmp(int a,int b)
{
    if(R[a]==R[b])
        return L[a]<L[b];
    return R[a]<R[b];
}

ll d(int l,int r)
{
    return 1ll*max(0,r-l+1);
}

int main()
{
    sync;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>L[i]>>R[i];
    zxr=2e9;
    zdl=0;
    for(int i=1;i<=n;i++)
    {
        if(R[i]<zxr)
        {
            zxr=R[pr=i];
        }
        if(L[i]>zdl)
        {
            zdl=L[pl=i];
        }
    }
    
    ll ans=0;
    
    for(int i=1;i<=n;i++)
    {
        if(i!=pl&&i!=pr)
        {
            ans=max(ans,d(zdl,zxr)+d(L[i],R[i]));
        }
    }
    
    for(int i=1;i<=n;i++)
    {
        id[i]=i;
    }
    sort(id+1,id+n+1,cmp);
    int p=0;
    for(int i=2;i<=n;i++)
    {
        p=max(p,L[id[i-1]]);
        ans=max(ans,d(zdl,R[id[i]])+d(p,zxr));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1408
X = int(input())
if X == 2:
    print(2)
else:
    def f(n):
        for i in range(3, int(n**0.5)):
            if n % i == 0:
                return True
        return False

    res = X
    if X % 2 == 0:
        res += 1

    while f(res):
        res += 2

    print(res)

Measured memory_bytes: 3188
n = int(input())
a = list(map(int,input().split()))

b = [-1] * n
l = 0
r = n-1
for i in range(n-1, -1, -1):
    if i % 2:
        b[l] = a[i]
        l += 1
    else:
        b[r] = a[i]
        r -= 1

if n % 2:
    b.reverse()
b = [str(i) for i in b]
print(' '.join(b))

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)2e5 + 9;
vector<int> T[N];
int f[N];
int res = 0;

void dfs(int u, int par){
  int mx1 = 0, mx2 = 0;
  for(auto x : T[u]){
    if(x == par) continue;
    dfs(x, u);
    f[u] = max(f[u], f[x] + 1);
    if(f[x]+1 >= mx1)
      mx2=mx1, mx1=f[x]+1;
    else if(f[x]+1 >= mx2)
      mx2 = f[x]+1;
  }
  res = max(res, mx1 + mx2);
}

int who[N];

int main(){
  fastIO;
  int n;
  cin >> n;
  int a, b;
  for(int i = 1; i < n; i ++ ){
    cin >> a >> b;
    T[b].push_back(a);
    T[a].push_back(b);
  }
  dfs(1,-1);
  who[0] = 1;
  for(int i = 1; i <= res; i ++ ){
    if(!who[i - 1]){
      who[i] = 1;
    }
    else if(i >= 2 && (!who[i-2])){
      who[i] = 1;
    }
  }
  if(who[res])
    cout << "First\n";
  else
    cout << "Second\n";
  return 0;
}


Measured memory_bytes: 27776
import scala.io.StdIn.readInt
import scala.collection.immutable.SortedMap

object Main {
  def main(args:Array[String]) = {
    val prices = SortedMap(2->380,3->550,5->850,10->1520,12->1870,15->2244)
    val dp = new Array[Int](51)
    for(i<-0 to 50 if i!=1) {
      for( (w,p) <- prices if i+w<=50) {
        if( dp(i+w)==0 || dp(i) + p < dp(i+w) ) {
          dp(i+w) = dp(i) + p
        }
      }
    }
    var n = 0
    while({n=readInt;n}!=0) {
      println(dp(n/100))
    }
  }
}

Measured memory_bytes: 43848
import math
import copy

# 0以上整数x「未満」の素数をリストに格納して返す
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

def realprimes(y):
    Y = primes(y)
    t = int((y + 1) / 2)
    bestprime = []

    for prime in Y:
        if prime != 2:
            prime2 = (prime + 1)//2
            pw = 0
            for i in range(2,int(math.sqrt(prime2)) + 2):
                if prime2 == 2:
                    break
                elif prime2 % i == 0:
                    pw = 1
                    break
            if pw == 0:
                bestprime.append(prime)

    T = bestprime
    V = set(Y) & set(T)
    return list(V)
W = realprimes(10**5 - 1)
W.sort()
W.append(10**5)
q = int(input())
s = []
for i in range(q):#h:高さ
    s.append([int(m) for m in input().split()])

j = 0
Z = []
for i in range(10 ** 5):
    if i < W[j]:
        Z.append(j)
    else:
        j += 1
        Z.append(j)

for i in range(q):
    if Z[s[i][0]] != Z[s[i][0] - 1]:
        print(Z[s[i][1]] - Z[s[i][0]] + 1)
    else:
        print(Z[s[i][1]] - Z[s[i][0]])

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve()
{
	int n;
	cin >> n;
	int a = n % 10;
	if ((a == 2) or (a == 4) or (a == 5) or (a == 7) or (a == 9))
	{
		cout << "hon";
	}
	

	if ((a == 0) or (a == 1) or (a == 6) or (a == 8))
		cout << "pon";

	if (a == 3)
		cout << "bon";
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	solve();
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define itn int
#define gI gi
#define int long long

using namespace std;

typedef long long ll;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int n, m, k, pri[100003], tot;

signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	for (int i = 2; i <= 200000; i+=1)
	{
		bool fl = true;
		for (int j = 2; j * j <= i; j+=1)
		{
			if (i % j == 0) {fl = false; break;}
		}
		if (fl) pri[++tot] = i;
	}
	n = gi();
	for (int i = 1; i <= tot; i+=1)
	{
		if (pri[i] >= n) {printf("%lld\n", pri[i]); return 0;}
	}
	return 0;
}



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

int main()
{
	int cnt = 0;
	string s, check;
	cin >> s;
	check = s;
	reverse(s.begin(), s.end());
	
	for (int i = 0; i < check.length(); ++i)
	{
		if (check[i] != s[i])
		{
			cnt++;
		}
	}
	
	cout << cnt/2 << endl;
	return 0;
}


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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a==5&&b==5&&c==7)||(a==5&&b==7&&c==5)||(a==7&&b==5&&c==5)){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

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

using namespace std;

int main(){

	int n,m;
	cin >> n >> m;

	int votes[n];

	for(int i=0;i<n;i++)
		cin >> votes[i];

	int sum = 0;
	for(int i=0;i<n;i++)
		sum += votes[i];

	float compFact = 0.25f/m * sum;

	int count = 0;
	int flag = 0;

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

		if((float)votes[i] >= compFact)
			count++;

		if(count == m){
			flag = 1;
			break;
		}
	}

	if(flag == 1)
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;

}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
h[0] -= 1
for i in range(1, len(h) - 1):
    if(h[i-1] < h[i]):
        h[i] -= 1
    if(h[i] > h[i+1]):
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 16172
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d,f,g[1001],h=0,j,i,z,x;
	scanf("%d %d",&a,&s);
	for(i=0;i<s;i++){
		scanf("%d %d",&d,&f);
		if(d<a) g[i]=a-d;
		else g[i]=0;
	}
	j=0;
	for(i=0;i<s;i++){
		if(j<g[i]){
			j=g[i];
			x=i;
		}
	}
	for(i=0;i<s;i++) if(i!=x) h+=g[i];
	printf("%d\n",h);
	return 0;
}

Measured memory_bytes: 2680
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int N;
    int max;
    int min;
    int diff;
    int i,j;
    int *ip;
    scanf("%d", &N);
    ip = (int *)malloc(N * sizeof(int));
    for(i = 0 ; i < N; i++){
        scanf("%d", &ip[i]);
    }
    max = ip[1]-ip[0];
    min = ip[0];
    for(i = 1 ; i < N; i++) {
        diff  = ip[i] - min;
        if( diff > max)
            max = diff;

        if(min > ip[i])
            min = ip[i];
    }
    printf("%d\n",max);
    return 0;
}


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

int n;
int x[1010], y[1010];
char f[2];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", &x[i], &y[i]);
		f[x[i] + y[i] & 1] = 1;
	}
	if (f[0] && f[1])
		puts("-1");
	else {
		printf("%d\n", 31 + f[0]);
		for (int j = 30; j >= -f[0]; --j)
			printf("%d%c", 1 << max(j, 0), j + f[0] ? ' ' : '\n');
		for (int i = 0; i < n; ++i) {
			for (int j = 30; j >= -f[0]; --j) {
				int t = 1 << max(j, 0);
				if (abs(x[i]) >= abs(y[i]))
					if (x[i] >= 0) {
						x[i] -= t;
						putchar('R');
					}
					else {
						x[i] += t;
						putchar('L');
					}
				else
					if (y[i] >= 0) {
						y[i] -= t;
						putchar('U');
					}
					else {
						y[i] += t;
						putchar('D');
					}
			}
			assert(x[i] == 0);
			assert(y[i] == 0);
			putchar('\n');
		}
	}
	return 0;
}



Measured memory_bytes: 3844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			//int N = Integer.parseInt(str);
			//StringBuilder sb = new StringBuilder();
			String[] s = str.split(" ",0);
			int N = Integer.parseInt(s[0]);
			int M = Integer.parseInt(s[1]);
			int K = Integer.parseInt(s[2]);
			int re = 0;
			for(int i = 0;i< N+1;i++) {
				if(re == 1) break;
				for(int j = 0;j<M+1;j++) {
					if(i == 0 || j == 0) {
						if(i*M+j*N== K) {
							System.out.println("Yes");
							re++;
							break;
						}
					}else if(i*M+j*N-2*(i*j) == K){
						System.out.println("Yes");
						re++;
						break;
					}
					if(i==N && j==M){
						System.out.println("No");
					}
				}
			}
//			String str = br.readLine();
//			if(str.length()< 4) {
//				System.out.println("No");
//			}else if(str.substring(0, 4).equals("YAKI")) {
//				System.out.println("Yes");
//			}else {
//				System.out.println("No");
//			}
//			System.out.println(sb);
//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}

}


Measured memory_bytes: 21588
a,b=map(int,input().split())
mindiv=1000000000
for i in range(a,b):
  for j in range(i+1,b+1):
    if i%2019==0 or j%2019==0:
      print(0)
      exit()
    else:
      mindiv=min(i*j%2019,mindiv)
print(mindiv)

Measured memory_bytes: 41068
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

  int h, n, a[100010];
  cin >> h >> n;
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  for(int i=0; i<n; i++){
    h-=a[i];
  }
  if(h>0){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

	return 0;
}

Measured memory_bytes: 640
n = int(input())
first = []
second = []
third = []
ten = [0] * n
for i in range(n) :
    tmp = list(map(int, input().split()))
    first.append(tmp[0])
    second.append(tmp[1])
    third.append(tmp[2])

for i in range(n) :
    if first.count(first[i]) == 1 :
        ten[i] += first[i]
    if second.count(second[i]) == 1 :
        ten[i] += second[i]
    if third.count(third[i]) == 1 :
        ten[i] += third[i]
    
    print(ten[i])


Measured memory_bytes: 5628
#include <iostream>
#include <vector>
#include <set>
#include <string>
//#include "./libb/lib.hpp"

using namespace std;

int main()
{
    int nn;
    cin >> nn;
    
    int ans = 0;
    //ans = nn;

    set<string> sary;
    string str_tmp;
    int sum = 0;

    for(int i = 0; i < nn; i++){
        cin >> str_tmp;
        sary.insert(str_tmp);
    }

    for(auto itr = sary.begin(); itr != sary.end(); ++itr){
        sum++;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 19084
N = input()
K = int(input())
dp= [[[0]*2 for i in range(len(N)+1)] for _ in range(len(N)+1)]
if len(N)<K:
  print(0)
  exit()
dp[0][0][0]=1
for i in range(len(N)):
  for j in range(len(N)):
    if int(N[i])!=0:
      dp[i+1][j+1][1]+=dp[i][j][1]*9+dp[i][j][0]*(int(N[i])-1)
      dp[i+1][j][1] += dp[i][j][1]+dp[i][j][0]
      dp[i+1][j+1][0] += dp[i][j][0] 
    if int(N[i])==0:
      dp[i+1][j+1][1] += dp[i][j][1]*9
      dp[i+1][j][1] += dp[i][j][1]
      dp[i+1][j][0] += dp[i][j][0]
print(dp[len(N)][K][0]+dp[len(N)][K][1])

Measured memory_bytes: 43116
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    }
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[derive(Clone)]
struct Edge(usize, usize);

struct Solver {
    color: Vec<usize>,
}

const DUMMY: usize = 9;

impl Solver {
    fn new(N: usize) -> Solver {
        Solver { color: vec![DUMMY; N] }
    }
    fn dfs(&mut self, i: usize, p: usize, acc: usize, g: &Vec<Vec<Edge>>) {
        if self.color[i] != DUMMY {
            return;
        }
        self.color[i] = acc;
        for &Edge(to, w) in &g[i] {
            if to == p {
                continue;
            }
            self.dfs(to, p, acc ^ w, g);
        }
    }
}

use std::iter::IntoIterator;

fn join_string<T, S>(elems: T) -> String
where
    T: IntoIterator<Item = S>,
    S: ToString,
{
    elems
        .into_iter()
        .map(|i| i.to_string())
        .collect::<Vec<String>>()
        .join(" ")
}

fn main() {
    input!{
        N: usize,
        uvw: [(usize1, usize1, usize); N-1],
    }
    let mut graph = vec![Vec::new(); N];
    for (u, v, w) in uvw {
        let w = w % 2;
        graph[u].push(Edge(v, w));
        graph[v].push(Edge(u, w));
    }
    let mut s = Solver::new(N);
    s.dfs(0, N+1, 0, &graph);
    for i in s.color {
        println!("{}", i);
    }
}


Measured memory_bytes: 22772
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
int h,w,k;
string s[20];
int calc(vector<bool> const& status){
  int res=0;
  vector<int> white(h,0);
  int cnt=0;
  rep(j,w){
    int buf=0;
    rep(i,h){
      if(status[i]||i==h-1){
        if(s[i][j]=='1')buf++;
        if(buf>k){
          res=inf;
          goto FINE;
        }
        if(white[i]+buf>k){
          cnt++;
          rep(kk,h){
            white[kk]=0;
          }
          buf=0;
          rep(ii,h){
            if(status[ii]||ii==h-1){
              if(s[ii][j]=='1')buf++;
              if(buf>k){
              res=inf;
              goto FINE;
              }
              white[ii]+=buf;
              buf=0;
            }
            else{
              if(s[ii][j]=='1')buf++;
            }
          }
          break;
        }
        white[i]+=buf;
        buf=0;
      }
      else{
        if(s[i][j]=='1')buf++;
      }
    }
    NEXT:;
  }
  res=cnt;
  rep(i,h-1){
    if(status[i])res++;
  }
  FINE:
  return res;
}
int solve(vector<bool> status,int cur){
  int res;
  if(cur==h-1){
    return calc(status);
  }
  else{
    res=solve(status,cur+1);
    status[cur]=true;
    res=min(res,solve(status,cur+1));
    return res;
  }
}
signed main(){
  cin>>h>>w>>k;
  rep(i,h){
    cin>>s[i];
  }
  vector<bool> status(h,false);
  int res=solve(status,0);
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

A, B, C = LI()

print(C-min(A-B, C))

Measured memory_bytes: 39152
#include <iostream>
#include <algorithm>
#include <math.h> 
using namespace std;
int main(){
  int N, T;
  int t[200100];
  cin >> N >> T;
  int ans = 0;
  for(int i = 0; i < N; i++){
    cin >> t[i];
  }
  
  for(int i = 0; i < N - 1; i++){
    if(t[i+1] - t[i] < T) ans += t[i+1] - t[i];
    if(t[i+1] - t[i] >= T) ans += T;
  }

  cout << ans + T << endl;
}

Measured memory_bytes: 1024
def main():
    from sys import stdin
    def input():
        return stdin.readline().strip()

    h, w = map(int, input().split())
    c = [[int(i) for i in input().split()] for _ in range(10)]
    a = [[int(i) for i in input().split()] for _ in range(h)]

    # Warshall-Floyd
    for k in range(10):
        for i in range(10):
            for j in range(10):
                if c[i][j] > c[i][k] + c[k][j]:
                    c[i][j] = c[i][k] + c[k][j]

    ans = 0
    for i in a:
        for j in i:
            if j == -1:
                continue
            else:
                ans += c[j][1]

    print(ans)

main()

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

int main(){
    long long n, m;
    cin >> n >> m;
    set<int> st;
    map<int, long long> mp;

    long long a, tmp;
    a = 0;
    long long ans = 0;
    for(int i = 0;i < n;i++){
        cin >> tmp;
        a = (a + tmp) % m;
        if(a == 0) ans++;
        st.insert(a);
        mp[a]++;
    }

    for(auto itr = st.begin();itr != st.end();itr++){
        ans += mp[*itr]*(long long)(mp[*itr]-1)/2ll;
    }

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




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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

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

    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if (S=="Sunny") {
    cout << "Cloudy" << endl;
  }

  else if (S=="Cloudy") {
    cout << "Rainy" << endl;
  }

  else {
    cout << "Sunny" << endl;
  }
}

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

n,m=map(int,input().split())

g=[[] for i in range(n)]
memo=[-1 for i in range(n)]

for i in range(m):
 x,y=map(int,input().split())
 x-=1
 y-=1
 g[x].append(y)

def rec(x):
 if memo[x]!=-1:
  return memo[x]

 res=0
 for i in g[x]:
  res=max(res,rec(i)+1)

 memo[x]=res
 return res

ans=0
for v in range(n):
 ans=max(ans,rec(v))
print(ans)

Measured memory_bytes: 59008
N, K = [int(_) for _ in input().split()]
TD = [[int(_) for _ in input().split()] for i in range(N)]

TD_sorted = sorted(TD, key=lambda x:-x[1])

d_sum = 0
t_set = set([])
d_surplus = []

for t, d in TD_sorted[:K]:
	d_sum += d
	if not t in t_set:
		t_set.add(t)
	else:
		d_surplus.append(d)

a = d_sum + len(t_set) ** 2
answer = a

for t, d, in TD_sorted[K:]:
	if not d_surplus:
		break
	if not t in t_set:
		a += 2 * len(t_set) + 1
		a += d
		a -= d_surplus.pop()
		t_set.add(t)
		answer = max(answer, a)

print(answer)

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

ll fac[MAX], finv[MAX], inv[MAX];

inline void init_nCk() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

inline ll nCk(int n, int k){
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	int x, y; cin >> x >> y;
	ll res = 0;
	if ((x + y) % 3 == 0) {
		int n = (x + y) / 3;
		int k = min(x, y) - n;
		init_nCk();
		res = nCk(n, k);
	}
	cout << res << '\n';
    return 0;
}


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

int main()
{
    int n; cin>> n;
    int a[n], b[n];
    for(int i = 0; i < n; i++)
        cin>> a[i];
    for(int i = 0; i < n; i++)
        cin>> b[i];
    int f = -1;
    bool ff;
    for(int i = 0; i < n; i++){
        if(a[i] < b[i]){
            f = 0;
            break;
        }else if(b[i] < a[i]){
            f = 1;
            break;
        }
    }
    if(f){
        for(int i = 0; i < n; i++)
            swap(a[i], b[i]);
    }
    int cnt = 0;

    do{
        ff = 1;
        for(int i = 0; i < n; i++){
            if(a[i] != b[i])
                ff = 0;
        }
        if(ff) break;
        cnt++;
    } while(next_permutation(a, a + n));

    cout<< cnt;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	string S;
	cin >> S;
	set<char> s;
	ALL_THE(S,it) s.insert(*it);
	if(s.count('N') || s.count('S')) 
		if(s.count('N') == 0 || s.count('S') == 0) {
			cout << "No\n";
			return 0;}
	if(s.count('E') || s.count('W')) 
		if(s.count('E') == 0 || s.count('W') == 0) {
			cout << "No\n";
			return 0;}
	cout << "Yes\n";
	return 0;}

// look at my code
// my code is amazing


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

int main() {
  ll n; cin >> n;
  if(n==1) cout << 1 << endl;
  else if(n<4) cout << 2 << endl;
  else if(n<8) cout << 4 << endl;
  else if(n<16) cout << 8 << endl;
  else if(n<32) cout << 16 << endl;
  else if(n<64) cout << 32 << endl;
  else cout << 64 << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,p;
    cin>>a>>p;
    a*=3LL; a+=p;
    a/=2LL;
    cout<<a;
      return 0;
}


Measured memory_bytes: 256