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

signed main(){
    int h,w;
    cin>>h>>w;
    int c[10][10];
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin >>c[i][j];
        }
    }
    int a[10]={},a0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a0;
            a[abs(a0)]++;
        }
    }
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
            }
        }
        
    }
    int ans=0;
    for(int i=0;i<10;i++){
        ans+=a[i]*c[i][1];
        //cerr<<a[i]<<' '<<c[i][1];
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ChenChuLing main
using namespace std;
char s[5004];
int k,l;
set<string>tr;
int ChenChuLing (){
    scanf("%s",s+1);
    l=strlen(s+1);
    int cnt=0;
    scanf("%d",&k);
    for(int i=1;i<=5;i++){
        for(int j=1;j+i-1<=l;j++){
            string m="";
            for(int t=j;t<=j+i-1;t++){
                m=m+s[t];
            }
            tr.insert(m);
        }
    }
    string s;
    for(set<string>::iterator it=tr.begin();it!=tr.end()&&k>0;it++,k--){
        s=(*it);
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int n,i,j,k,orderlen,strlen;
  string order,str,tempstr1,tempstr2;
  char temp;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> order;
    reverse(order.begin(),order.end());
    cin >> str;
    orderlen=order.size();
    strlen=str.size();
    for(j=0;j<orderlen;j++){
      if(order[j]=='J'){
    temp=str[strlen-1];
    for(k=strlen-1;k>=1;k--){
      str[k]=str[k-1];
    }
    str[0]=temp;
      }
      else if(order[j]=='C'){
    temp=str[0];
    for(k=0;k<strlen-1;k++){
      str[k]=str[k+1];
    }
    str[strlen-1]=temp;
      }
      else if(order[j]=='E'){
    tempstr1=tempstr2="";
    for(k=0;k<strlen;k++){
      if(k<strlen/2) tempstr1+=str[k];
      else tempstr2+=str[k];
    }
    str="";
    str+=tempstr2;
    str+=tempstr1;
    if(strlen%2==1){
      temp=str[0];
      for(k=0;k<strlen/2;k++){
        str[k]=str[k+1];
      }
      str[strlen/2]=temp;
    }
      }
      else if(order[j]=='A'){
    reverse(str.begin(),str.end());
      }
      else if(order[j]=='P'){
    for(k=0;k<strlen;k++){
      if('1'<=str[k]&&str[k]<='9') str[k]-=1;
      else if(str[k]=='0') str[k]='9';
    }
      }else{//M
    for(k=0;k<strlen;k++){
      if('0'<=str[k]&&str[k]<='8') str[k]+=1;
      else if(str[k]=='9') str[k]='0';
    }
      }
    }
    cout << str << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>

int n;
int a[100010];
int b[100010];
int l;
int r;
long long count;

int main(void)
{
	scanf("%d", &n);
	
	for(int i = 0 ; i < n + 1 ; i++)
	{
		scanf("%d", &a[i]);
	}
	
	for(int i = 0 ; i < n ; i++)
	{
		scanf("%d", &b[i]);
	}
	
	for(int i = 0 ; i < n ; i++)
	{
		if(b[i] >= a[i])
		{
			count += a[i];
			b[i] -= a[i];
			a[i] = 0;
		}
		
		else
		{
			count += b[i];
			b[i] = 0;
		}
		
		if(b[i] != 0)
		{
			if(b[i] <= a[i + 1])
			{
				a[i + 1] -= b[i];
				count += b[i];
			}
			
			else
			{
				count += a[i + 1];
				a[i + 1] = 0;
			}
		}
	}
	
	printf("%lld", count);
	return 0;
}

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

typedef long long ll;
#define mp make_pair
#define pb push_back
#define pi pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	int t=1;
	//cin>>t;
	while(t--){
	 ll n,x;
	 cin>>n>>x;
	 ll sum=0;
	 ll a[n];
	 for(int i=1;i<=n;i++) cin>>a[i];
	 for(int i=2;i<=n;i++)
	 {
	 	ll t=a[i]+a[i-1];
	 	if(t<=x) continue;
	 	t-=x;
	 	sum+=t;
	 	
	 	ll mintake=min(a[i],t);
	 	a[i]-=mintake;
	 }
	 cout<<sum<<endl;
	}		
}

Measured memory_bytes: 4400
N, A, B, C = map(int,input().split())
l = [int(input()) for i in range(N)]
INF = 10**9

def dfs(cur, a, b, c):
  if cur==N:
    return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c) > 0 else INF
  ret0 = dfs(cur+1, a, b, c)
  ret1 = dfs(cur+1, a+l[cur], b, c)+10
  ret2 = dfs(cur+1, a, b+l[cur], c)+10
  ret3 = dfs(cur+1, a, b, c+l[cur])+10
  return min(ret0, ret1, ret2, ret3)

print(dfs(0,0,0,0))

Measured memory_bytes: 3064
if __name__ == '__main__':

	l = input()
	S1, S2 = [], []
	
	sum = 0
	n = len(l)
	for i in range(n):
		if l[i] == "\\":
			S1.append(i)
		elif l[i] == "/" and S1:
			j = S1.pop()
			a = i - j
			sum += a
	
			while S2 and S2[-1][0] > j:
				a += S2.pop()[1]
			S2.append([j, a])
	
	print(sum)
	print(len(S2), *(a for j, a in S2))


Measured memory_bytes: 6516
#include<stdio.h>
int main()
{
    int x,y,cost;
    scanf("%d%d",&x,&y);
    if(x>=1 || x<=100 || y>=1 || y<=100 )
    {
        if(y%2==0)
        {
            cost=x+(y/2);
            printf("%d\n",cost);
        }
    }
    return 0;
}


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

int main() {
	int n, nSum = 0;
	std::cin >> n;
	int m = n;
	for (int i = 0;i < 9;i++) {
		if (n >= 1 && n < 10) {
			break;
		}
		nSum += n % 10;
		n = n / 10;
	}
	nSum += n;
	if (m%nSum == 0) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a,b,c,d;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
        d=a;
        a=b;
        b=d;
    }else{
        
    }
    if(b>c){
        d=b;
        b=c;
        c=d;
    }else{
        
    }
    if(a>b){
        d=a;
        a=b;
        b=d;
    }else{
        
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int i = 1;
  int x;
  int n; cin >> n;

  while (i <= n) {
    if (0 == i % 3) {
      cout << " " << i;
    } else if (3 == i % 10) {
      cout << " " << i; 
    } else if (30 < i) {
      x = i;
      while (x = x / 10) {
        if (3 == x % 10) {
          cout << " " << i;
          break;
        }
      }
    } 
    i++;
  }

  cout << endl;

  return 0;
}


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

int main()
{       
        int N,K;
        int l[70];
        
        cin >> N >> K;
        for(int i=0;i<N;++i){
                cin >> l[i];
        }       
        sort(l,l+N,greater<int>());
        
        int ans = 0;
        for(int i=0;i<K;++i){
                ans+=l[i];
        }       
        cout << ans << endl;
}       

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX 30
#define NIL -1

struct Node_struct {
  int p, l, r;
};

typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];
int H[MAX];

void print(int u) {
  int i, d = 0;
  printf("node %d: parent = %d, sibling = ", u, T[u].p);
  if (T[u].p == NIL) printf("-1, ");
  else if ((T[T[u].p].l != NIL) && (T[T[u].p].l != u)) printf("%d, ",T[T[u].p].l);
  else if ((T[T[u].p].r != NIL) && (T[T[u].p].r != u)) printf("%d, ",T[T[u].p].r);
  else printf("-1, ");
  if (T[u].l != NIL) d++;
  if (T[u].r != NIL) d++;
  printf("degree = %d, depth = %d, height = %d, ", d, D[u], H[u]);
  if (T[u].p == NIL) printf("root\n");
  else if ((T[u].l == NIL) && (T[u].r == NIL)) printf("leaf\n");
  else printf("internal node\n");
}

void calcDepth(int u, int p) {
  D[u] = p;
  if (T[u].l != NIL) calcDepth(T[u].l, p + 1);
  if (T[u].r != NIL) calcDepth(T[u].r, p + 1);
}

int calcHeight(int u) {
  int h1 = 0, h2 = 0;
  if (T[u].l != NIL) h1 = calcHeight(T[u].l) + 1;
  if (T[u].r != NIL) h2 = calcHeight(T[u].r) + 1;
  if (h1 > h2) H[u] = h1;
  else H[u] = h2;
  return H[u];
}

int main() {
  int i, n, root = 0, v, l, r;
  memset(T, NIL, sizeof(T));
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d%d%d", &v, &l, &r);
    if (l != NIL) {
      T[v].l = l;
      T[l].p = v;
    }
    if (r != NIL) {
      T[v].r = r;
      T[r].p = v;
    }
  }
  for (i = 0; i < n; i++) {
    if (T[i].p == NIL) {
      root = i;
      break;
    }
  }
  calcDepth(root, 0);
  calcHeight(root);
  for (i = 0; i < n; i++) print(i);
  return 0;
}



Measured memory_bytes: 2100
#include<iostream>
using namespace std;
int gcd(int ,int);
int main(){
  int x,y,a;
  cin>>x>>y;
  a=gcd(x,y);
  cout<<a<<endl;
  return 0;
}
 
int gcd(int x,int y){
  while(x!=y)
    if(x>y){
      x%=y;
      if(x==0) return y;
    }
    else{
      y%=x;
      if(y==0) return x;
    }
  return x;
}

Measured memory_bytes: 1164
//copied
#include "bits/stdc++.h"
using namespace std;
const int N = 5e5 + 5;
int n , d;
int arr[N];
int dis[N];
long long ans[N];
void calc(int idx){
	if(abs(ans[idx + 1] - arr[idx]) > ans[idx + 1]){
		ans[idx] = ans[idx + 1];
	}
	else{
		ans[idx] = ans[idx + 1] + arr[idx];
		if(arr[idx] - ans[idx + 1] >= ans[idx + 1]){
			ans[idx] = min(ans[idx] , arr[idx] - ans[idx + 1]);
		}
	}
}
int main(){
	scanf("%d %d" , &n , &d);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" , arr + i);
	}
	dis[0] = d;
	for(int i = 1 ; i <= n ; ++i){
		dis[i] = min(dis[i - 1] , abs(dis[i - 1] - arr[i]));
	}
	ans[n + 1] = 1;
	for(int i = n ; i >= 1 ; --i){
		calc(i);
	}
	int q;
	scanf("%d" , &q);	
	while(q--){
		int inp;
		scanf("%d" , &inp);
		if(dis[inp - 1] >= ans[inp + 1]){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
}

Measured memory_bytes: 9728
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

int X;
int ans;

void solve(){
	if(X==2 || X==3){
		ans = X;
		return;
	}
	if(X==4){
		ans = 5;
		return;
	}
	for(int i=X;i<=100003;i++){
		for(int n=2;n<i/2;n++){
			if(i%n==0) break;
			if(n==i/2-1){
				ans = i;
				return;
			}
		}
	}
}

int main(){
	cin >> X;

	solve();

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	long long h, w;
	cin >> h >> w;

	if (h == 2 || w == 2) {
		cout << 0 << endl;
	} else if (h == 1) {
		if (w == 1) {
			cout << 1 << endl;
		} else {
			cout << w - 2 << endl;
		}
	} else if (w == 1) {
		cout << h - 2 << endl;
	} else {
		cout << (w - 2) * (h - 2) << endl;
	}

	return 0;
}

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

int main() {
  
  string x,y;
  cin >> x >> y;
  
  if (x[0] == y[2] && x[1] == y[1] && x[2] == y[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<String> list = new ArrayList<String>();
		while(scan.hasNext()){
			double[] x = new double[3];
			double[] y = new double[3];
			for(int i = 0; i < 3; i++){
				x[i] = scan.nextDouble();
				y[i] = scan.nextDouble();
			}

			double xp = scan.nextDouble();
			double yp = scan.nextDouble();

			for(int i = 0; i < 3; i++){
				x[i] = x[i] - xp;
				y[i] = y[i] - yp;
			}

			double[] gaiseki = new double[3];
			gaiseki[0] = x[0]*y[1] - y[0]*x[1];
			gaiseki[1] = x[1]*y[2] - y[1]*x[2];
			gaiseki[2] = x[2]*y[0] - y[2]*x[0];

			int plus = 0;
			int minus = 0;
			for(int i = 0; i < 3; i++){
				if(gaiseki[i] > 0)plus++;
				if(gaiseki[i] < 0)minus++;
			}

			String ans = "NO";
			if(plus == 3 || minus == 3)ans = "YES";
			list.add(ans);
		}

		for(String s : list){
			System.out.printf("%s\n", s);
		}
	}
}

Measured memory_bytes: 32592
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
import heapq
INF = float("inf")
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

def custom_round(number, ndigits=0):
  if type(number) == int: #整数ならそのまま返す
    return number
  d_point = len(str(number).split('.')[1]) #小数点以下が何桁あるか定義
  if ndigits >= d_point:#求める小数点以下の値が引数より大きい場合はそのまま返す
    return number
  c = (10 ** d_point) * 2
    #小数点以下の桁数分元の数に0を足して整数にして2倍するための値(0.01ならcは200)
  return round((number * c + 1) / c, ndigits)
    #元の数に0を足して整数にして2倍して1を足して2で割る。元の数が0.01なら0.015にしてroundを行う

N = ii()
As = list(mi())

for i in range(N):
  As[i] -= (i + 1)
  
As.sort()

if N % 2 == 1:
  median = As[(N-1)//2]
else:
  median = (As[(N-1)//2] + As[(N-1)//2 + 1]) // 2

ans = 0
for a in As:
  ans += abs(median - a)
  
print(ans)

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

int main(){
    int h, w, n, i, j, count = 0, index = 0;
    cin >> h >> w >> n;
    int a[n], c[h][w];
    for (i=0; i<n; i++){
        cin >> a[i];
    }
    for (i=0; i<h; i++){
        for (j=0; j<w; j++){
            if (a[index] == count){
                index++;
                count = 0;
            }
            if (i%2 == 0){
                c[i][j] = index+1;
            }else{
                c[i][w-j-1] = index+1;
            }
            count++;
        }
        cout << "\n";
    }
    for (i=0; i<h; i++){
        for (j=0; j<w; j++){
            cout << c[i][j] << " ";
        }
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 384
def judge(ll):
    for i in range(1,int(len(ll))-1):
        for j in range(1,int(len(ll[0]))-1):
            #print(i,j)
            if ll[i][j] == '#' and ll[i - 1][j] == '.' and ll[i][j - 1] == '.' and ll[i + 1][j] == '.' and ll[i][j + 1] == '.':
                return False
    #print(ll)
    return True


h, w = map(int, input().split())
s_ij = [['.' for i in range(w + 2)]]
s_ij += [list('.' + input() + '.') for i in range(h)]
s_ij.append(['.' for i in range(w + 2)])

print("Yes" if judge(s_ij) else "No")


Measured memory_bytes: 3064
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val m = sc.nextInt
    val q = sc.nextInt
    val a = Array.ofDim[Int](q)
    val b = Array.ofDim[Int](q)
    val c = Array.ofDim[Int](q)
    val d = Array.ofDim[Int](q)
    (0 until q).foreach { i =>
      a(i) = sc.nextInt
      b(i) = sc.nextInt
      c(i) = sc.nextInt
      d(i) = sc.nextInt
    }

    println(new QC(n, m, q, a, b, c, d).solve)
  }
}

class QC(n: Int, m: Int, q: Int, a: Array[Int], b: Array[Int], c: Array[Int], d: Array[Int]) {
  def solve: Int = {
    val array = Array.fill[Int](n)(1)
    var ans = 0
    var break = false

    def countup(index: Int, indexUp: Boolean): Unit = {
      if (array(index) < m) {
        val next = array(index) + 1
        if (indexUp) {
          (index until n).foreach(array(_) = next)
        } else {
          array(index) = next
        }
      } else {
        countup(index - 1, true)
      }
    }

    while (!break) {
      ans = Math.max(ans, calc(array))
      break = array(0) == m
      if(!break) {
        countup(n - 1, false)
      }
    }
    ans
  }

  private def calc(array: Array[Int]) = {
    (0 until q).foldLeft(0) { (acc, cur) =>
      if (array(b(cur) - 1) - array(a(cur) - 1) equals c(cur)) {
        acc + d(cur)
      } else {
        acc
      }
    }
  }
}

Measured memory_bytes: 57260
n = int(input())
b = list(map(int, input().split()))

ans = []


while b:
    for i in range(len(b)-1, -1, -1):
        if b[i] == i+1:
            ans.append(i+1)
            del b[i]
            break
    else:
        print(-1)
        exit()
print(*ans[::-1], sep='\n')


Measured memory_bytes: 9084
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
    int n,ans;
    float a[100],sum=0.0,ave,sa;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%f",&a[i]);
        sum+=a[i];
    }
    ave=sum/n;
    ans=0;
    sa=fabs(ave-a[0]);
    for(int i=1;i<n;i++){
        if(sa>fabs(ave-a[i])){
            sa=fabs(ave-a[i]);
            ans=i;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
from bisect import bisect, bisect_left
inf = float('inf')

A,B,Q = map(int,input().split())
S = [-inf] + [int(input()) for _ in range(A)] + [inf]
T = [-inf] + [int(input()) for _ in range(B)] + [inf]
X = [int(input()) for _ in range(Q)]

def solve(x):
    si = bisect(S,x)
    sl,sr = S[si-1],S[si]
    ti = bisect(T,x)
    tl,tr = T[ti-1],T[ti]
    ans = inf
    for s in [sl,sr]:
        for t in [tl,tr]:
            res0 = abs(s-x) + abs(s-t)
            res1 = abs(t-x) + abs(s-t)
            ans = min(ans,res0,res1)
    return ans

for x in X:
    ans = solve(x)
    print(ans)

Measured memory_bytes: 16144
N, M = map(int, input().split())

A = [list(input()) for i in range(N)]
B = [list(input()) for i in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        flag = True
        for k in range(M):
            if A[i+k][j:j+M] != B[k]:
                flag = False
                break
        if flag:
            print('Yes')
            exit()
print('No')


Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  ll h,w;cin>>h>>w;
  vvl a(h,vl(w));
  rep(i,h){
    rep(j,w)cin>>a[i][j];
  }
  vl x;
  vl y;
  vl nx;
  vl ny;
  rep(i,h){
    if(i%2==0){
      rep(j,w){
        if(a[i][j]%2==1){
          if(i==h-1&&j==w-1)continue;
          else if(j==w-1){
            a[i+1][w-1]++;
            y.push_back(i);
            x.push_back(w-1);
            ny.push_back(i+1);
            nx.push_back(w-1);
          }
          else {
            a[i][j+1]++;
            y.push_back(i);
            x.push_back(j);
            ny.push_back(i);
            nx.push_back(j+1);
          }
        }
      }
    }
    if(i%2==1){
      for(ll j=w-1;j>=0;j--){
        if(a[i][j]%2==1){
          if(i==h-1&&j==0)continue;
          else if(j==0){
            a[i+1][0]++;
            y.push_back(i);
            x.push_back(0);
            ny.push_back(i+1);
            nx.push_back(0);
          }
          else {
            a[i][j-1]++;
            y.push_back(i);
            x.push_back(j);
            ny.push_back(i);
            nx.push_back(j-1);
          }
        }
      }
    }
  }
      
            
        
        
       
  cout<<x.size()<<endl;
  rep(i,x.size()){
    cout<<y[i]+1<<" "<<x[i]+1<<" "<<ny[i]+1<<" "<<nx[i]+1<<endl;
  }
}
    
        

Measured memory_bytes: 8148
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9

struct edge{
    ll to,cap,cost,rev;
    edge(){}
    edge(ll to,ll cap,ll rev):to(to),cap(cap),rev(rev){}
    edge(ll to,ll cap,ll cost,ll rev):to(to),cap(cap),cost(cost),rev(rev){}
};

typedef vector<vector<edge> > graph;
struct Dinic{
    ll n;
    graph g;
    vector<ll> level,iter;
    Dinic() {}
    Dinic(ll n): n(n){
	g.resize(n);
	level.resize(n);
	iter.resize(n);
    }
    void add_edge(ll from, ll to, ll cost){
	g[from].push_back(edge(to,cost,g[to].size()   ) );
	g[to].push_back(edge(from,0,g[from].size() -1 ) );
    }
    void bfs(ll s){
	fill(level.begin(),level.end(),-1);
	queue<ll> q;
	q.push(s);
	level[s] = 0;
	while(!q.empty()){
	    ll tmp = q.front();
	    q.pop();
	    for(ll i=0;i<g[tmp].size();i++){
		edge &e = g[tmp][i];
		if(e.cap > 0 && level[e.to] < 0){
		    level[e.to] = level[tmp] + 1;
		    q.push(e.to);
		}
	    }
	}
    }
    ll dfs(ll v,ll t,ll f){
	if( v == t ) return f;
	for(ll &i = iter[v]; i < g[v].size() ; i++){
	    edge &e = g[v][i];
	    if( e.cap > 0 && level[v] < level[e.to] ){
		ll d = dfs(e.to, t, min(f,e.cap) );
		if( d > 0 ){
		    e.cap -= d;
		    g[e.to][e.rev].cap += d;
		    return d;
		}
	    }
	}
	return 0;
    }
    ll max_flow(ll s,ll t){
	ll flow = 0, f;
	while(1){
	    bfs(s);
	    if(level[t] < 0) return flow;
	    fill(iter.begin(),iter.end() , 0);
	    for(f = dfs(s,t,inf); f > 0; f = dfs(s,t,inf) ) flow += f;
	}
    }
};



int main(){
    ll x,y,e;
    cin>>x>>y>>e;
    ll S = x + y;
    ll T = x + y + 1;
    Dinic f(x+y+2);
    for(int i=0;i<x;i++)f.add_edge(S,i,1);// sorce から　Xの集合へ
    for(int i=0;i<y;i++)f.add_edge(x+i,T,1);// Yの集合からsinkへ
    for(ll i=0;i<e;i++){
	ll s,t;
	cin>>s>>t;
	f.add_edge(s,x+t,1);// X to Y
    }
    cout<<f.max_flow(S,T)<<endl;
    return 0;
}



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

vector<bool> isp(1000005 , true);
vector<int> p;

void soe() {
	isp[0] = isp[1] = false;
  	for(int i = 2; i*i <= 1000005; i++) {
    	if(isp[i]) {
        	for(int j = i*i; j < 1000005; j += i) isp[j] = false;
        }
    }
  	for(int i = 2; i < 1000005; i++) if(isp[i]) p.push_back(i);
}

int main() {
  	soe();
	int x;
  	cin >> x;
  	cout << *lower_bound(p.begin() , p.end() , x) << "\n";
  	return 0;
}



Measured memory_bytes: 1020
main = do
    getLine
    (h1:h) <- map read . words <$> getLine :: IO [Int]
    putStrLn $ if f h1 h then "Yes" else "No"
  where
    f m []   = True
    f m (hi:h) =
        if m <= hi then f (max m hi) h
        else if (m-1) <= hi then f (max m hi) h
        else False


Measured memory_bytes: 36220
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int x[100000], y[100000];

struct edge{
  int to;
  int c;
};

int main(){
  int n;
  cin >> n;
  vector<pair <int, int> > vx, vy;
  vector<struct edge> v[n];
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &x[i], &y[i]);
    vx.push_back(make_pair(x[i], i));
    vy.push_back(make_pair(y[i], i));
  }
  sort(vx.begin(), vx.end());
  sort(vy.begin(), vy.end());

  int prev;
  for (int i = 0; i < n; i++) {
    if (i == 0) prev = vx[i].second;
    else {
      struct edge e = {vx[i].second, vx[i].first - x[prev]};
      v[prev].push_back(e);
      e = {prev, vx[i].first - x[prev]};
      v[vx[i].second].push_back(e);
      prev = vx[i].second;
    }
  }

  for (int i = 0; i < n; i++) {
    if (i == 0) prev = vy[i].second;
    else {
      struct edge e = {vy[i].second, vy[i].first - y[prev]};
      v[prev].push_back(e);
      e = {prev, vy[i].first - y[prev]};
      v[vy[i].second].push_back(e);
      prev = vy[i].second;
    }
  }
  priority_queue<pair<int, int> > pq;
  vector<int> s(n, -1);
  for (int i = 0; i < v[0].size(); i++) {
    struct edge e = v[0][i];
    pq.push(make_pair(-e.c, e.to));
  }
  while(!pq.empty()){
    pair<int, int> e = pq.top(); pq.pop();
    if (s[e.second] != -1) continue;
    if (s[e.second] == -1) {
      for (int i = 0; i < v[e.second].size(); i++) {
        struct edge u = v[e.second][i];
        pq.push(make_pair(-u.c, u.to));
      }
    }
    s[e.second] = -e.first;
  }
  int count = 0;
  for (int i = 1; i < n; i++) {
    count += s[i];
  }
  cout << count << endl;
  return 0;
}


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

int main(){
	int a, b;
	while(cin >> a >> b){
		int c = a, d = b, p1 = c, p2 = d;
		while(a%b != 0){
			int tmp = a;
			a = b;
			b = tmp%b;
		}
		while(c != d){
			if(c < d)
				c += p1;
			else
				d += p2;
		}
		cout << b << ' ' << c << endl;
	}
    return 0;
}


Measured memory_bytes: 3104
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (31 - __builtin_clz(x))
#define SZ(x) ((int)(x).size())
#define BACK(x) prev((x).end())
#define HASK(x, y) ((x).find(y) != (x).end())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 1 << 19;

char T[maxN];

void solve()
{
	int p, q ;
	scanf ("%d%d", &p, &q);
	if (p > q)
		swap(p, q);
	while (q--)
		printf("%d", p);
	printf("\n");
}
 
int main()
{
	int t = 1;
	//scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}





Measured memory_bytes: 3800
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int):
    A, B, C = sorted([A, B, C,])
    return A if A != B else C


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    print(solve(A, B, C))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define ll long long
const int MOD = 1e9 + 7;
const int INF  = 2e9 + 5;
const int LEN = 5005;
bool cmp(ii a, ii b) {
	return a.fi + a.se < b.fi + b.se;
}
// codefestival 2017 - D
// Link : https://cf17-final.contest.atcoder.jp/tasks/cf17_final_d

// proof
/*
	greedy :
	h1 + w1 < h2 + w2
*/
int n;
int dp[LEN][LEN];
ii ar[LEN];
// dp[pref][used] = min cost

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i =0;i<n;i++) {
    	int a,b;
    	cin>>a>>b;
    	ar[i] = {a,b};
    }

    for(int i =0;i<LEN;i++) {
    	for(int k =1;k<LEN;k++)
    		dp[i][k] = INF;
    }

    sort(ar,ar+n,cmp);
    for(int i =1;i<=n;i++) { // pref
    	for(int k =1; k <= i;k++) {
    		if(ar[i-1].fi >= dp[i-1][k-1])
    			dp[i][k] = min(dp[i-1][k], dp[i-1][k-1] + ar[i-1].se); // take it or not
    		else
    			dp[i][k] = dp[i-1][k];// cannot take newer one
    	} // used
    }
    int ans=0;
    for(int i =0;i<=n;i++) {
    	if(dp[n][i] != INF)
    		ans = i;
    }
    cout<<ans<<"\n";

    return 0;   	
}

Measured memory_bytes: 98176
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        l: u64,
        r: u64,
        d: u64,
    }

    let mut ans = 0;
    for i in l..=r {
        if i % d == 0 {
            ans += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2112
// Do you knOW what it feels like?

		// To be TorTured by your own MinD?
	
	// I don't wanna feel the PAIN.

// I BeG you KILLING me, pleASE...

#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())

typedef long long ll;
typedef pair<ll,ll> pll;

const ll maxn=1e5+10, mod=1e9+7, inf=1e18;

vector<ll> g[maxn];

set<pll> all;
ll out[maxn];
bool mk[maxn];

void pfs(ll v=1){
	mk[v]=1;
	for(auto u:g[v])if(!mk[u]){
		out[min(v,u)]--;
		all.erase({min(v,u),max(v,u)});
		pfs(u);
		if(out[u]%2){
			out[u]++;
			all.insert({u,v});
		}
		else{
			out[v]++;
			all.insert({v,u});
		}
	}
}

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

	ll n,m; cin>>n>>m;

	ll v,u;
	for(int i=0;i<m;i++){
		cin>>v>>u;

		if(v>u) swap(v,u);
		g[v].pb(u), g[u].pb(v);

		all.insert({v,u});
		out[v]++;
	}

	if(m%2) return cout<<-1, 0;

	pfs();

	for(auto x:all) cout<<x.F<<' '<<x.S<<endl;

	return 0;
}






















Measured memory_bytes: 24960
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    int w[n];
    for (int i = 0; i < n; i++)
    {
        /* code */
        cin>>w[i];
            }
    int ans1=99999999;
    int s[10000];
    s[0]=0;
        for (int i = 1; i <= n; i++)
    {
        /* code */
        s[i]=s[i-1]+w[i-1];
    }
    for (int i = 1; i < n; i++)
    {
        /* code */
        ans1=min(ans1,abs(s[n]-s[i]*2));

    }
    
    cout<<ans1<<endl;
 
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(T) (T).begin(), (T).end()
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
ll intmax = (1LL<<32)-1;
const int INF = 1e9 + 5;


class fastio{
public:
	fastio(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	}
} __fastio;

template <typename T>
T abs(T x){
	if(x < 0) return -x;
	else return x;
}

template <typename T>
void swap(T &a, T &b){
	T temp;
	temp = a;
	a = b;
	b = temp;
}

const int MX = 2001;

void solve() {
	
}

int main() {
	string s;
	bool answer = false;
	cin >> s;
	for(int i=0; i<3; i++) {
		for(int j=i+1; j<3; j++) {
			if(s[i] != s[j])
				answer = true;
		}		
	}
	cout << ((answer)?("Yes\n"):("No\n"));
}


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

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

  int H;
  int ans = 0;
  int max = 0;

  for (int i = 0; i < N; i++)
  {
    cin >> H;

    if (H >= max)
    {
      max = H;
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int num[1000000];
int main()
{
    for(int i=1;i<=100;++i){
        for(int j=1;j<=100;++j){
            for(int k=1;k<=100;++k){
                num[i*i+j*j+k*k+i*j+j*k+i*k]++;
            }
        }
    }
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        cout<<num[i]<<endl;
}

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

int main(){
  long i,N,x;cin>>N;
  vector<long> cnt(4,0);
  for(i=0;i<N;i++){
    cin>>x;
    cnt[x%4]++;
  }
  if(cnt[2])cnt[2]=1;
  if(cnt[0]+1<cnt[1]+cnt[2]+cnt[3]){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,a,b;
  cin >> k >> a >> b;
  for(int i=0; i<100; i++){
    if(k*i >=a && k*i <=b){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}


Measured memory_bytes: 3600
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		BigInteger A[] = new BigInteger[N];
		BigInteger m = A[0] = new BigInteger(sc.next());
		BigInteger gcd;

		for (int i = 1; i < N; i++) {
			A[i] = new BigInteger(sc.next());
			gcd = A[i].gcd(m);
			m = A[i].multiply(m).divide(gcd);
		}

		m = m.subtract(BigInteger.ONE);

		BigInteger fMax = BigInteger.ZERO;

		for (int i = 0; i < N; i++) {
			fMax = fMax.add(m.remainder(A[i]));
		}

		System.out.println(fMax);

		return;
	}
}


Measured memory_bytes: 62656
n = int(input())
n_l = list(map(int, input().split()))

VORDER = 10 ** 18
ans = 1

if 0 in n_l:
    ans = 0
else:
    for i in n_l:
        ans = i * ans
        if ans > VORDER:
            ans = -1
            break

print(ans)


Measured memory_bytes: 21608
#![allow(unused_imports, non_snake_case, dead_code)]
use proconio::{
    input, fastout,
    marker::{Chars, Bytes, Usize1}
};

const MODULO: u64 = 1_000_000_007;

struct Combination {
    MOD: u64,
    size: usize,
    fact: Vec<u64>,
    inv_fact: Vec<u64>,
}
impl Combination {
    fn new(size: usize, MOD: u64) -> Self {
        let mut fact = vec![1; size + 1];
        let mut inv_fact = vec![1; size + 1];
        for i in 1..size + 1 {
            fact[i] = fact[i - 1] * i as u64 % MOD;
        }
        inv_fact[size] = Self::modpow(fact[size], MOD - 2, MOD);
        for i in (1..size + 1).rev() {
            inv_fact[i - 1] = inv_fact[i] * i as u64 % MOD;
        }
        Combination {
            MOD,
            size,
            fact,
            inv_fact,
        }
    }
    fn modpow(mut x: u64, mut y: u64, m: u64) -> u64 {
        let mut res: u64 = 1;
        while y > 0 {
            if y & 1 > 0 {
                res = res * x % m;
            }
            x = x * x % m;
            y >>= 1;
        }
        res
    }
    fn modinv(x: u64, m: u64) -> u64 {
        Self::modpow(x, m - 2, m)
    }
    fn nPr(&self, n: usize, r: usize) -> u64 {
        if n < r {
            return 0;
        };
        self.fact[n] * self.inv_fact[n - r] % self.MOD
    }
    fn nCr(&self, n: usize, r: usize) -> u64 {
        if n < r {
            return 0;
        };
        self.fact[n] * self.inv_fact[r] % self.MOD * self.inv_fact[n - r] % self.MOD
    }
}

#[fastout]
fn main() {
    input!{
        N: usize
    }
    let ncr = Combination::new(N * 2, MODULO);
    let mut ans = 0;
    for i in 1..N/3+1 {
        ans = (ans + ncr.nCr(N-i*3+i-1, i-1)) % MODULO;
    }
    println!("{}", ans);

}


Measured memory_bytes: 2212
N = int(input())
if N>=100 and N<=111:
    print(111)
if N>=112 and N<=222:
    print(222)
if N>=223 and N<=333:
    print(333)
if N>=334 and N<=444:
    print(444)
if N>=445 and N<=555:
    print(555)
if N>=556 and N<=666:
    print(666)
if N>=667 and N<=777:
    print(777)
if N>=778 and N<=888:
    print(888)
if N>=889 and N<=999:
    print(999)


Measured memory_bytes: 3064
n,W = map(int,input().split())
w = []
v = []
for _ in range(n):
    weight,value = map(int,input().split())
    w.append(weight)
    v.append(value)

INF = float("inf")
order = 10**5  + 1 
dp = [[INF] * order for _ in range(n+1)] #dp[i+1][value] i番目まで選んで価値をvalue以上にする時の重さの最小値
dp[0][0] = 0

for i in  range(n):
    for value in range(order):
        if value-v[i]>= 0:
            dp[i+1][value] = min(dp[i+1][value],dp[i][value-v[i]] + w[i])
        dp[i+1][value] = min(dp[i+1][value],dp[i][value])

ans = 0
for value in range(order):
    if dp[n][value] <= W:
        ans = max(ans,value)
print(ans)

Measured memory_bytes: 312632
#include <cstdio>           // printf(), scanf()
#include <cstring>          // memset()
#include <vector>
#include <algorithm>        // min()

using namespace std;
static const int MAX_V = 100;
static const int INF = 100000000;

typedef struct edge_tbl
{
	int to, cap;
	unsigned long rev;
} edge;

vector<edge> G[MAX_V];
bool used[MAX_V];

int
dfs(int v, int t, int f)
{
	if (v == t)
		return f;

	used[v] = true;
	for (unsigned int i = 0; i < G[v].size(); ++i)
	{
		edge &e = G[v][i];
		if (!used[e.to] && e.cap > 0)
		{
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0)
			{
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}

	return 0;
}

int
max_flow(int s, int t)
{
	int flow = 0;
	while (true)
	{
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0)
			return flow;

		flow += f;
	}
}

int
main(int argc, char** argv)
{
	int V, E;
	int u, v, c;

	scanf("%d %d", &V, &E);
	for (int i = 0; i < E; ++i)
	{
		scanf("%d %d %d", &u, &v, &c);
		G[u].push_back((edge){v, c, G[v].size()});
		G[v].push_back((edge){u, 0, G[u].size() - 1});
	}

	printf("%d\n", max_flow(0, V - 1));
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
const ll INF = 1061109567;
const double EPS = 1e-10;
int main(){

    int D;
    cin>>D;
    cout<<D+D*D+D*D*D<<endl;
    
    return 0;
}


Measured memory_bytes: 3584
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

vector<int> sieve_of_eratosthenes(int n) {
    vector<int> primes(n);
    for (int i = 2; i < n; ++i)
        primes[i] = i;
    for (int i = 2; i*i < n; ++i)
        if (primes[i])
            for (int j = i*i; j < n; j+=i)
                primes[j] = 0;
    primes.erase(std::remove(primes.begin(), primes.end(), 0), primes.end());
    return primes;
}

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    cin >> n;

    VI prime = sieve_of_eratosthenes(n+1);
    VI count(prime.size(),0);
    FOR(i,2,n+1){
        int t = i;
        while(t!=1){
            for (int j = 0; j < prime.size(); ++j) {
                if(t%prime[j]==0){
                    count[j]++;
                    t/=prime[j];
                    break;
                }
            }
        }
    }

    int ans = 1;
    REP(i,count.size()){
        ans*=count[i]+1;
        ans%=MOD;
    }

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


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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);	//各ダムの降水量
	vector<int> ans(n);	//各山の降水量
	for(int i=0;i<n;i++){
		cin >> a[i];
		//基準のとなる山の降水量を求める
		//奇数番目は足して偶数番目は引く
		if(i%2==0) ans[0]+=a[i];
		else ans[0]-=a[i];
	}
	for(int i=1;i<n;i++){
		//漸化式を元に代入
		ans[i]=2*a[i-1]-ans[i-1];
	}
	for(auto&& e:ans) cout << e << " ";
	cout << "\n";
	return 0;
}

Measured memory_bytes: 2048
'''input
5 1
00010
'''


N, K=map(int,input().split())
Sstr=input()
# print(Sstr)
S=[]

for i in range(N):
	S.append(int(Sstr[i]))

# print(S)
# flip=0
# for i in range(N-1):
# 	flip+=abs(S[i+1]-S[i])
# print(flip)


now=1
cnt=0
Nums=[]
for i in range(N):
	if S[i]==now:
		cnt+=1
	else:
		Nums.append(cnt)
		now=1-now
		cnt=1

if cnt!=0:
	Nums.append(cnt)

if(len(Nums)%2==0):
	Nums.append(0)

Add=2*K+1
ans=0

left=0
right=0
tmp=0

for i in range(0, len(Nums), 2):
	# tmp=0
	Nextleft=i
	Nextright=min(i+Add, len(Nums))
	# for j in range(left, right):
	# 	tmp+=Nums[j]
	while(Nextleft>left):
		tmp-=Nums[left]
		left+=1
	while(Nextright>right):
		tmp+=Nums[right]
		right+=1
	
	ans=max(tmp,ans)

print(ans)

Measured memory_bytes: 4860
#include <stdio.h>

int dp[50];

int fib(int n)
{
    if (n == 0 || n == 1)
        return dp[n] = 1;
    if (dp[n] != -1)
        return dp[n];
    return dp[n] = fib(n - 1) + fib(n - 2);
}

int main()
{
    int n, i;
    for (i = 0; i < 50; i++)
        dp[i] = -1;

    scanf("%d", &n);
    printf("%d\n", fib(n));

    return 0;
}


Measured memory_bytes: 2720
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    vvl A(N,vl(M+1,0));
    vl now(N,0);
    rep(i,N){
        rep(j,M){
            cin >> A[i][j];
        }
    }
    ll ans=N;
    set<int> st;
    while(now[0]!=M){
        vl cnt(301,0);
        rep(i,N){
            cnt[A[i][now[i]]]++;
        }
        ll res=0;
        FOR(i,1,301){
            chmax(res,cnt[i]);
        }
        chmin(ans,res);
        FOR(i,1,301){
            if(res==cnt[i]){
                st.insert(i);
            }
        }
        rep(i,N){
            while(st.count(A[i][now[i]])){
                now[i]++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4376
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N;
    cin>>N;
    int a,b,c;
    a=N/100;
    N%=100;
    b=N/10;
    N%=10;
    c=N;
    if(a==7||b==7||c==7){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3600
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		ArrayList<String> s = nextCharArray();
		ArrayList<String> t = nextCharArray();
		int output = 100000;
		for(int i = 0; i < s.size() - t.size() + 1; i++){
			int count = 0;
			for(int j = 0; j < t.size(); j++){
				if(!s.get(i + j).equals(t.get(j))){
					count++;
				}
			}
			output = Math.min(output, count);
		}
		myout(output);
	}
	//Method addition frame start




	//Method addition frame end
}


Measured memory_bytes: 33536
#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

int stack[10000];
int top = 0;

bool isEnpty(){
    return top == 0;
}

void push(int x){
    top++;
    stack[top] = x;
}

int pop(){
    if(isEnpty()){
        cout << "underflow" << endl;
        return 0;
    }
    top--;
    return stack[top + 1];
}

int main(){
    int a, b;
    string s;
    while(cin >> s){
        if(cin.eof()) break;
        if(s == "+"){
            a = pop();
            b = pop();
            push(b + a);
        } else if(s == "-"){
            a = pop();
            b = pop();
            push(b - a);
        } else if(s == "*"){
            a = pop();
            b = pop();
            push(b * a);
        } else if(s == "/"){
            a = pop();
            b = pop();
            push(b / a);
        } else {
            push(atoi(s.c_str()));
        }
    }
    cout << pop() << endl;
    return 0;
}


Measured memory_bytes: 3148
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int A, B, M;
  cin >> A >> B >> M;

  vector<int> a(A);
  int min_A = 100001;
  for (int i = 0; i < A; i++) {
    cin >> a[i];
    min_A = min(a[i], min_A);
  }

  vector<int> b(B);
  int min_B = 100001;
  for (int i = 0; i < B; i++) {
    cin >> b[i];
    min_B = min(b[i], min_B);
  }

  int min_sum = min_A + min_B;
  for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    min_sum = min(a[x - 1] + b[y - 1] - c, min_sum);
  }

  cout << min_sum << endl;
  
  return 0;
}


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

using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    int res = 1;
    int min = v[0];
    for(int i=1; i<n; i++){
        if(v[i] < min){
            min = v[i];
            res++;
        } 
    }
    cout << res << "\n";
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(),c=0;
		String s = sc.next();	
		n++;
		c++;
		for(int i = 1;i<s.length();i++){
			if(i-1==s.length()-1){
				break;
			}
			else if(s.charAt(i-1)!=s.charAt(i))
				c++;
		}
		System.out.println(c);
	}

}

Measured memory_bytes: 23844
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1001001001;

using namespace std;
using ll = long long;
typedef pair<int, int> P;



int main(){
    int n, m, x;
    cin >> n >> m >> x;
    int a[n][m+1];
    rep(i, n){
        rep(j, m+1) cin >> a[i][j];
    }


    
    int min_count=INF;
    for(int bit=0; bit<(1<<n); bit++){
        vector<int> s(m+1);
        int count=0;
        for(int i=0; i<n; i++){
        if(bit &(1<<i)){
            count+=a[i][0];
            for(int j=1; j<=m; j++) s[j]+=a[i][j];
        }
        }
        bool flag=true;
        for(int k=1; k<m+1; k++){
            if(s[k]<x) {flag=false;break;}
        }
        if(flag==true){
            if(min_count>count) min_count=count;
        }
    }

    if(min_count==1001001001) out(-1);
    else out(min_count);
}


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

using namespace std;

using ll = long long;

int main() {

  ll n; cin >> n;
  ll ans = 0;
  for(ll i = 2; i * i <= n; ++i){
    ll cnt = 0;
    ll kanta = 1;
    while(n % i == 0){
        n = n / i;
        cnt++;
        if(cnt >= kanta){
            cnt = 0;
            kanta++;
            ans++;
        }
    }
  }
  if(n != 1)ans++;
  cout << ans;
  return 0;
}


Measured memory_bytes: 3608
n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]

kaidan = [True for _ in range(n+1)]
dp = [0 for _ in range(n+1)]

for i in a:
    kaidan[i] = False

dp[0] = 1
dp[1] = 1 if kaidan[1] else 0

for i in range(2,n+1):
    if kaidan[i]:
        dp[i] = (dp[i-1] + dp[i-2]) % 1000000007
    else:
        dp[i] = 0
print(dp[-1])

Measured memory_bytes: 8616