akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int main() {

    unsigned long long a, b;
    cin >> a >> b;

    cout << bitset<32>(a & b) << endl;
    cout << bitset<32>(a | b) << endl;
    cout << bitset<32>(a ^ b) << endl;


}



Measured memory_bytes: 3164
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
A = int(math.sqrt(N))

while True:
	if N%A == 0:
		B = N//A
		print(max(len(str(A)),len(str(B))))
		break
	A -= 1


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


int main(){
    int d,w;
    while(cin>>d>>w){
        if(d==0 && w==0){
            break;
        }
        int e[d][w];
        for(int i=0;i<d;i++)for(int j=0;j<w;j++){
            cin>>e[i][j];
        }
        int ans=0;
        //長方形のサイズ
        for(int y=3;y<=d;y++)for(int x=3;x<=w;x++){
            //長方形の始点(左上)
            for(int sty=0;sty<=d-y;sty++)for(int stx=0;stx<=w-x;stx++){
                int m = 100; //外側の最小値
                int M = 0; //内側の最大値
                for(int i=sty;i<sty+y;i++)for(int j=stx;j<stx+x;j++){
                    if(i==sty || i==sty+y-1){
                        m = min(m,e[i][j]);
                    }
                    else if(j==stx || j==stx+x-1){
                        m = min(m,e[i][j]);
                    }
                    else M = max(M,e[i][j]);
                }
                int ret = 0;
                if(M >= m) continue;
                for(int i=sty+1;i<sty+y-1;i++)for(int j=stx+1;j<stx+x-1;j++){
                    ret += m - e[i][j];
                }
                ans = max(ans,ret);
            }
        }
        cout << ans <<endl;
    } 
                
}


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

int main(){
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  for(int i = 0;i<ty-sy;i++){
    cout<<"U";
  }
  for(int i = 0;i<tx-sx;i++){
    cout<<"R";
  }
  for(int i = 0;i<ty-sy;i++){
    cout<<"D";
  }
  for(int i = 0;i<=tx-sx;i++){
    cout<<"L";
  }
  for(int i = 0;i<=ty-sy;i++){
    cout<<"U";
  }
  for(int i = 0;i<=tx-sx;i++){
    cout<<"R";
  }
  cout<<"D";
  cout<<"R";
  for(int i = 0;i<=ty-sy;i++){
    cout<<"D";
  }
  for(int i = 0;i<=tx-sx;i++){
    cout<<"L";
  }
  cout<<"U";





  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=list(map(int,input().split()))
a[0]=a[0]%m
for i in range(n-1):
    a[i+1]=(a[i]+a[i+1])%m
result=0
for i in range(n):
    if a[i]==0:
        result+=1

a.sort()
num=a[0]
b=0
for i in range(n):
    if a[i]==num:
        b+=1
    else:
        result+=b*(b-1)/2
        b=1
        num=a[i]
print(int(result+b*(b-1)/2))

Measured memory_bytes: 14252
#include <stdio.h>
#include <algorithm>
using namespace std;

int pow(int a,int n){
	if(n <= 0){
		return 1;
	}
	return a * pow(a,n - 1);
}

int main(){
	int v1,v2;
	int a[10];
	int sum1;
	int sum2;
	int ans = 0;
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9],&v1,&v2) != EOF){
		sum1 = 0;
		sum2 = 0;
		for(int i = 0; i < 10; i++){
			sum1 += a[i];
		}
		for(int i = 0; i < 10; i++){
			sum2 += a[i];
			if(sum1 * v1 > sum2 * (v1 + v2)){
				ans = i + 2;
			}
		}
		printf("%d\n",ans);
	}
	///////////////////////////////////
	//Sleep(200000);///////////////////// 提出するときは必ず外す！
	///////////////////////////////////
	return 0;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m;
    cin>>n>>m;
    if(n%3==0||m%3==0)
    {
        puts("0");
        return 0;
    }
    long long ans=min((m%3ll)*n,(n%3ll)*m);
    for(int i=1;i<n;i++)
    {
        long long a=i*m,b=(m)/2*(n-i),c=(m-m/2)*(n-i);
        long long maxn=max(max(a,b),c),mix=min(a,min(b,c));
        ans=min(maxn-mix,ans);
    }
    for(int i=1;i<n;i++)
    {
        long long a=i*m,b=(n-i)/2*(m),c=(n-i-(n-i)/2)*(m);
        long long maxn=max(max(a,b),c),mix=min(a,min(b,c));
        ans=min(maxn-mix,ans);
    }
    for(int i=1;i<m;i++)
    {
        long long a=i*n,b=(n)/2*(m-i),c=(n-n/2)*(m-i);
        long long maxn=max(max(a,b),c),mix=min(a,min(b,c));
        ans=min(maxn-mix,ans);
    }
    for(int i=1;i<m;i++)
    {
        long long a=i*n,b=(m-i)/2*(n),c=(m-i-(m-i)/2)*(n);
        long long maxn=max(max(a,b),c),mix=min(a,min(b,c));
        ans=min(maxn-mix,ans);
    }
    cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 256
s = input().split(" ")
n = int(s[0])
m = int(s[1])
a = [["" for i in range(m)]for j in range(n)]
b = []
c = []
for i in range(n):
    s = input().split(" ")
    for j in range(m):
        a[i][j] = int(s[j])
for i in range(m):
    b.append(int(input()))
for i in range(n):
    seki = 0
    for j in range(m):
        seki += a[i][j] * b[j]
    c.append(seki)
for i in range(n):
    print(c[i])

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

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

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

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;
const int maxn = 305, P = 998244353;
char str[maxn];
int len, n, m, A[maxn], dp[2][maxn][maxn], val1[maxn][maxn], val2[maxn][maxn];

void Add(int &x, int y) {
  x += y;
  if (x >= P) x -= P;
}

void solve() {
  scanf("%s %d", str + 1, &m);
  len = strlen(str + 1), n = 1;
  chkmin(m, len);
  rep(i, 1, len) {
    if (str[i] == '0') {
      n++;
    } else {
      A[n]++;
    }
  }
  dp[0][0][0] = 1;
  int sel = 1, sum = 0;
  per(i, n, 1) {
    memset(dp[sel], 0, sizeof dp[sel]);
    sum += A[i];
    rep(j, 0, sum) {
      rep(k, 0, min(m, sum)) {
        val1[j][k] = ((j ? val1[j - 1][k] : 0) + dp[sel ^ 1][j][k]) % P;
//        val2[k - j][]
      }
    }
    rep(j, 0, sum) {
      rep(k, j, min(m, sum)) {
        dp[sel][j][k] = (1ll * val1[sum][k] - (j ? val1[j - 1][k] : 0) + P) % P;
//        rep(p, j, sum) Add(dp[sel][j][k], dp[sel ^ 1][p][k]);
        rep(t, 1, min(A[i], j)) Add(dp[sel][j][k], dp[sel ^ 1][j - t][k - t]);
//        printf("(%d %d %d) %d\n", i, j, k, dp[sel][j][k]);
      }
    }
    sel ^= 1;
  }
  int res = 0;
  rep(k, 0, m) Add(res, dp[sel ^ 1][0][k]);
  cout << res << endl;
}

int main() {
//  int T = read();
//  while (T--) solve();
  solve();
  return 0;
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  string str;
  cin>>str;

  if(N%2 == 1) cout<<"No"<<endl;
  else{
    string a = str.substr(0, N/2);
    string b = str.substr(N/2);
    cout<<(a == b? "Yes":"No")<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

map<vi,int> mp;
map<vi,int> mq;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi vec(n);
    rep(i,n){
        cin >> vec[i];
        --vec[i];
    }
    mp[vec] = 0;
    vector<vector<int> > st[2];
    st[0].pb(vec);
    rep(i,4){
        st[1].clear();
        rep(id,len(st[0])){
            rep(j,n-1){
                srep(k,j+1,n){
                    vi res = st[0][id];
                    for(int l=j;2*l<j+k;l++){
                        swap(res[l],res[j+k-l]);
                    }
                    if(mp.find(res) == mp.end()){
                        mp[res] = i+1;
                        st[1].pb(res);
                    }
                }
            }
        }
        swap(st[0],st[1]);
    }
    vector<vector<int> > su[2];
    vi res(n);
    iota(all(res),0);
    mq[res] = 0;
    su[0].pb(res);
    int ans = INF;
    if(mp.find(res) != mp.end()){
        cout << mp[res] << "\n";
        return 0;
    }
    rep(i,4){
        su[1].clear();
        rep(id,len(su[0])){
            rep(j,n-1){
                srep(k,j+1,n){
                    vi res = su[0][id];
                    for(int l=j;2*l<j+k;l++){
                        swap(res[l],res[j+k-l]);
                    }
                    if(mp.find(res) != mp.end()){
                        cmn(ans,mp[res]+i+1);
                    }else if(mq.find(res) == mq.end()){
                        mq[res] = i+1;
                        su[1].pb(res);
                    }
                }
            }
        }
        swap(su[0],su[1]);
    }
    if(ans == INF){
        cout << "9\n";
    }else{
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 102084
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	int a,b,c; cin>>a>>b>>c;
	cout<<min(b,c)<<" ";
	int d=b+c;
	cout<<max(d-a,0)<<endl;
	return 0;
}

Measured memory_bytes: 3620
H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]
ans = 0
# ビット探索
for i in range(2**H):
    for j in range(2**W):
        cnt = 0
        for h in range(H):
            for w in range(W):
                if((i >> h) & 1) == 0 and ((j >> w) & 1) == 0:
                    if C[h][w] == "#":
                        cnt += 1
        if cnt == K:
            ans += 1

print(ans)


Measured memory_bytes: 9016
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define CLR(array) memset( array, 0, sizeof array )
typedef long long int ll;

int main(){
	std::string S,T,U;
	int A,B;

	std::cin >> S >> T;
	std::cin >> A >> B;
	std::cin >> U;

	if( U == S )
		printf("%d %d\n", A-1, B );
	else
		printf("%d %d\n", A, B-1);
}

Measured memory_bytes: 256
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;

class Solver extends Main{
	Solver(){
		
	}
}//Solver_end

@SuppressWarnings("unchecked")
class Main{
	static int imax=Integer.MAX_VALUE;
	static long lmax=Long.MAX_VALUE;
	
	public static void main(String[] args) throws FileNotFoundException{
		
		Scanner sc=new Scanner(System.in);
		int[] num=readlnI(sc," ");
		
		int[] a=new int[101];
		int[] b=new int[101];
		
		for(int i=num[0]; i<num[1]; i++){
			a[i]=1;
		}
		for(int i=num[2]; i<num[3]; i++){
			b[i]=1;
		}
		
		int c=0;
		for(int i=0; i<101; i++){
			if(a[i]==1 && b[i]==1){
				c++;
			}
		}
		
		puts(c);

	}//main_end
	
//---------------------------------------------------------------------------
	static int readI(Scanner sc){
		return Integer.parseInt(sc.nextLine().trim());
	}
	static long readL(Scanner sc){
		return Long.parseLong(sc.nextLine().trim());
	}
	static String readS(Scanner sc){
		return sc.nextLine().trim();
	}
	static int[] readlnI(Scanner sc, String dl){
		return Arrays.stream(sc.nextLine().trim().split(dl)).mapToInt(Integer::parseInt).toArray();
	}
	static long[] readlnL(Scanner sc, String dl){
		return Arrays.stream(sc.nextLine().trim().split(dl)).mapToLong(Long::parseLong).toArray();
	}
	static String[] readlnS(Scanner sc, String dl){
		return sc.nextLine().trim().split(dl);
	}
	@SuppressWarnings("unchecked")
	static <T> void puts(T... args){
		for(int i=0; i<args.length-1; i++){
			System.out.printf("%s ",args[i]);
		}
		System.out.println(args[args.length-1]);
	}
	static void puts(int[] ary){
		for(int i=0; i<ary.length-1; i++){
			System.out.printf("%d ",ary[i]);
		}
		System.out.println(ary[ary.length-1]);
	}
	static void puts(long[] ary){
		for(int i=0; i<ary.length-1; i++){
			System.out.printf("%d ",ary[i]);
		}
		System.out.println(ary[ary.length-1]);
	}
	static void bs(){
		System.out.println("");
	}
	static int sum(int[] ary){
		int sum=0;
		for(int i=0; i<ary.length; i++) sum+=ary[i];
		return sum;
	}
	static long sum(long[] ary){
		long sum=0;
		for(int i=0; i<ary.length; i++) sum+=ary[i];
		return sum;
	}
	static void tblSort(int[][] tbl){
		Arrays.sort(tbl, new Comparator<int[]>(){
			@Override
			public int compare(int[] a, int[] b){
				if(a[0]==b[0]){
					return b[1]-a[1];
				}else{
					return b[0]-a[0];
				}
			}
		});
	}
}


Measured memory_bytes: 28112
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int d=max(max(a,b),c);
  int e=min(min(a,b),c);
  int f=a+b+c-d-e;
  cout<<((d*2-e-f)%2==0? (d*2-e-f)/2:(d*2-e-f)/2+2)<<endl;
}

Measured memory_bytes: 3596
n = int(input())
w = [int(i) for i in input().split()]

S1 = []
S2 = []
for i in range(n - 1):
  S1.append(sum(w[:i + 1]))
  S2.append(sum(w[i + 1:]))


ABS = []
for i in range(len(S1)):
  ABS.append(abs(S1[i] - S2[i]))

print(min(ABS))

Measured memory_bytes: 3064
def dfs(v,start):
    check=a[start-1]
    for i in v[start]:
        if(a[i-1]>=check):
            return 0
    return 1
        





n,m=map(int,input().split())
a=list(map(int,input().split()))
route=[[] for i in range(n+1)]
for i in range(m):
    x,y=map(int,input().split())
    route[x].append(y)
    route[y].append(x)
ans=0
visited=[0 for i in range(n+1)]
for i in range(1,n+1):
        ans+=dfs(route,i)
        
print(ans)


Measured memory_bytes: 30132
#include<bits/stdc++.h>
using namespace std;
int cnt=1,h[3005],dis[3005],pre[3005],inq[3005],S,T,N,tot,id[55][55];
struct Edge {
	int to,next,flow,cost;
} e[1000005];
void Add_Edge(int x,int y,int z,int w) {
	e[++cnt]=(Edge) {y,h[x],z,w};
	h[x]=cnt;
	e[++cnt]=(Edge) {x,h[y],0,-w};
	h[y]=cnt;
}
bool SPFA(int s,int t) {
	memset(inq,0,sizeof(inq));
	memset(pre,0,sizeof(pre));
	memset(dis,0xc0,sizeof(dis));
	queue<int> q;
	q.push(s),inq[s]=1,dis[s]=0;
	while(!q.empty()) {
		int now=q.front();
		q.pop(),inq[now]=0;
		for(int i=h[now]; i; i=e[i].next) {
			if(!e[i].flow)continue;
			int y=e[i].to;
			if(dis[y]<dis[now]+e[i].cost) {
				dis[y]=dis[now]+e[i].cost,pre[y]=i;
				if(!inq[y])q.push(y),inq[y]=1;
			}
		}
	}
	return dis[t]>-1e9;
}
int Adjust(int t,int s) {
	int dlt=1e9;
	for(int i=t; i!=s; i=e[pre[i]^1].to)dlt=min(dlt,e[pre[i]].flow);
	for(int i=t; i!=s; i=e[pre[i]^1].to)e[pre[i]].flow-=dlt,e[pre[i]^1].flow+=dlt;
	return dlt*dis[t];
}
int EK(int s,int t) {
	int ret=0;
	while(SPFA(s,t))ret+=Adjust(t,s);
	return ret;
}
int n,m;
char str[55][55];
struct P{
	int x,y;
};
void bfs(int i,int j,int p){
	queue<P> q;
	int o[55][55]={0};
	q.push({i,j});
	while(!q.empty()){
		P x=q.front();
		q.pop();
		Add_Edge(p,id[x.x][x.y],1,abs(x.x-i)+abs(x.y-j));
		if(x.x+1<=n&&!o[x.x+1][x.y]&&str[x.x+1][x.y]!='#'){
			q.push({x.x+1,x.y});
			o[x.x+1][x.y]=1;
		}
		if(x.y+1<=m&&!o[x.x][x.y+1]&&str[x.x][x.y+1]!='#'){
			q.push({x.x,x.y+1});
			o[x.x][x.y+1]=1;
		}
	}
}
int main(){
	cin>>n>>m;
	S=1,T=tot=2;
	for(int i=1;i<=n;i++){
		cin>>str[i]+1;
		for(int j=1;j<=m;j++)id[i][j]=++tot,Add_Edge(tot,T,1,0);
	}
	for(int i=n+m;i>=2;i--){
		for(int j=i;j>=1;j--){
			if(j>m||i-j<1||i-j>n)continue;
			if(str[i-j][j]!='o')continue;
			bfs(i-j,j,++tot);
			Add_Edge(S,tot,1,0);
			//cout<<i-j<<' '<<j<<' '<<ans<<endl;
		}
	}
	cout<<EK(S,T);
    return 0;
}


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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define yes "Yes"
#define yse "Yes"
#define no "No"

#define pb push_back
#define mp make_pair

#define NIL -1

#define list_itr list<ll>::iterator

#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define rep_cs(i, l, n) for (int i = (l); i <= (n); i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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

const int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(v.begin(), v.end());
// int sum = accumulate(v, v + v.size(), 0);

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

bool binary_search(int a[], int n, int key)
{
    int l = 0;
    int r = n;
    int middle;
    while (l < r)
    {
        middle = (l + r) / 2;
        if (key == a[middle])
        {
            return true;
        }

        if (key > a[middle])
        {
            l = middle + 1;
        }
        else if (key < a[middle])
        {
            r = middle;
        }
    }
    return false;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

void com_init()
{
    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;
    }
}

long long combination(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;
}

const int MAX_C = 1000;
long long Com[MAX_C][MAX_C];

void combination_for_small()
{
    memset(Com, 0, sizeof(Com));
    Com[0][0] = 1;
    for (int i = 1; i < MAX_C; ++i)
    {
        Com[i][0] = 1;
        for (int j = 1; j < MAX_C; ++j)
        {
            Com[i][j] = (Com[i - 1][j - 1] + Com[i - 1][j]) % MOD;
        }
    }
}

bool isPalindrome(string s)
{
    string t = s;
    reverse(t.begin(), t.end());
    return s == t;
}

int find(int i)
{
    ll sum = 0;

    while (i > 0)
    {
        sum += i % 10;
        i = i / 10;
    }
    return sum;
}

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    rep_cs(i, 1, n)
    {
        ll tmp = find(i);
        if (a <= tmp && tmp <= b)
        {
            ans += i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
  int n,m,wa=0,ac=0; scanf("%d%d",&n,&m);
  int a[n],w[n];
  for(int i=0; i<n; i++){
    a[i]=0; w[i]=0;
  }
  for(int i=0; i<m; i++){
    int t; scanf("%d",&t);
    char k[3]; scanf("%s",k);
    if(a[t-1]==1) continue;
    if (strcmp(k,"WA")==0) w[t-1]++;
    else if(strcmp(k,"AC")==0){
      a[t-1]=1; ac++; wa+=w[t-1];
    }
    //printf("%s %d\n",k,t);
  }
  printf("%d %d\n",ac,wa);
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int a, b;
  cin >> a >> b;
  string aa(b, '0' + a), bb(a, '0' + b);
  cout << min(aa, bb) << endl;
  return 0;
}

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

void swap(int* a, int* b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

int sort(int* &num, int size)
{
    int flag = 1;
    int step = 0;
    while(flag)
    {
        flag = 0;
        for(int j = size - 1; j > 0; j--)
        {
            if(num[j] < num[j - 1])
            {
                swap(&num[j], &num[j - 1]);
                step++;
                flag = 1;
            }
        }
    }
    return step;
}

int main()
{
    int size = 0;
    cin >> size;
    int *num = new int[size];
    for(int i = 0; i < size; i++)
    {
        cin >> num[i];
    }
    int step = sort(num, size);
    for(int t = 0; t < size; t++)
    {
        if(t)
            cout << " ";
        cout << num[t];
    }
    cout << endl;
    cout << step << endl;
    return 0;
}


Measured memory_bytes: 3072
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.next();
        String[] list = {"eraser", "erase", "dreamer", "dream"};

        for(String l: list){
            line = line.replaceAll(l, "");
        }

        if(line.length() != 0){
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    }
}


Measured memory_bytes: 28616
#include<stdio.h>
int main(){
int a[4],b[4],i;
double x,y;
for(i=0;i<4;i++){
a[i]=0;
b[i]=0;
}
while(scanf("%lf %lf\n",&x,&y)!=EOF){
if(x>=1.1){
a[0]++;
}
else if(x>=0.6){
a[1]++;
}
else if(x>=0.2){
a[2]++;
}
else{
a[3]++;
}
if(y>=1.1){
b[0]++;
}
else if(y>=0.6){
b[1]++;
}
else if(y>=0.2){
b[2]++;
}
else{
b[3]++;
}
}
for(i=0;i<4;i++){
printf("%d %d\n",a[i],b[i]);
}
return 0;
}


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

int main(){
    vector<int> a;
    int q;
    cin>>q;
    while(q--){
        int y,x;
        cin>>y;
        switch(y){
            case 0:cin>>x;a.push_back(x);break;
            case 1:cin>>x;cout<<a[x]<<endl;break;
            case 2:a.pop_back();break;
        }
    }
    return 0;
}


Measured memory_bytes: 3888
A, B, M = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
xyc = [[int(i) for i in input().split()] for _ in range(M)]
ans = min(a) + min(b)
for z in xyc:
    x, y, c = z
    ans = min(a[x - 1] + b[y - 1] - c, ans)
print(ans)

Measured memory_bytes: 80236
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
int main()
{
	int n;
	int a[105];
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	int ans=0;
	int tot=1;	
	for(int i=2;i<=n;i++) 
	{
		if(a[i]==a[i-1]) tot++;
		else
		{
			ans=ans+tot/2;
			tot=1;
		}
	}
	ans+=tot/2;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int D = keyboard.nextInt();
		int N = keyboard.nextInt();
		
		int ans = 0;
		
		
		if(D == 0) {
			if(N%100 != 0) {
				ans = N;
			}else {
				ans = 101;
			}
		}else if(D == 1) {
			if(N%100 != 0) {
				ans = 100*N;
			}else {
				ans = 10100;
			}
		}else if(D == 2) {
			if(N%100 != 0) {
				ans = 100*100*N;
			}else {
				ans = 1010000;
			}
		}
		
		
		System.out.print(ans);
		keyboard.close();	
		
	}
}


Measured memory_bytes: 35640
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

struct Person{
	Person(){
		lock_data = wait_data = -1;
		check = false;
	}
	int lock_data,wait_data;
	bool check;
};

struct Data{
	Data(){
		lock_person = -1;
	}
	int lock_person;
};

int main(){
	int n;

	Person person[101];
	Data data[101];

	char info[5];
	int left,right;

	scanf("%d",&n);

	for(int i = 0; i < n; i++){
		scanf("%d %s %d",&left,info,&right);

		if(info[0] == 'w'){
			person[left].wait_data = right;
		}else{
			person[left].lock_data = right;
			data[right].lock_person = left;
		}
	}

	bool FLG = false;
	int tmp;
	for(int i = 1; i <= 100; i++){
		if(person[i].wait_data != -1){
			person[i].check = true;
			tmp = data[person[i].wait_data].lock_person;

			while(person[tmp].check == false && person[tmp].wait_data != -1){
				person[tmp].check = true;
				tmp = data[person[tmp].wait_data].lock_person;
			}

			if(person[tmp].check == true){
				FLG = true;
				break;
			}else{
				//tmp????§£?????????
				person[i].check = false;
				tmp = data[person[i].wait_data].lock_person;

				while(person[tmp].wait_data != -1){
					person[tmp].check = false;
					tmp = data[person[tmp].wait_data].lock_person;
				}
			}
		}
	}

	if(!FLG){
		printf("0\n");
	}else{
		printf("1\n");
	}
	return 0;
}

Measured memory_bytes: 2624
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] V = new int[N];
		int[] C = new int[N];
		for (int i = 0; i < N; i++)
			V[i] = sc.nextInt();
		for (int i = 0; i < N; i++)
			C[i] = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < N; i++) {
			if (V[i] > C[i])
				ans += V[i] - C[i];
		}

		System.out.println(ans);

	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  int a = 0,ans = -1;
  for(int i=1;i<=N;i++){
    if(vec.at(a) == 2){
      ans = i;
      break;
    }
    a = vec.at(a)-1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
 
int main(){
  int H, N;
  cin >> H >> N;
  int wa=0;
  int a;
  for(int i=0; i<N; i++) {
    cin >> a;
    wa += a;
  }
  if(H<=wa) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;

int main(){
	
	int n,x;
	
	cin >> n >> x;
	
	vector<int> a(n);
	int b = 0;
	
	for(int i=0;i<n;i++){
		cin >> a[i];
		b += a[i];
	}
	
	int min = *min_element(a.begin(),a.end());
	int j = 1;
	
	while(1){
		if(min*j > x-b)
			break;
		j++;
	}
	
	cout << n+j-1;
	
	return 0;
}

Measured memory_bytes: 256
s=list(input())
k=int(input())
c=0
ind=-1
indx=-1
f=True
for i in range(len(s)):
  if s[i]=='1':
    c+=1
  else:
    ind=i
    indx=s[i]
    f=False
    break
if f or k<ind+1:
  print(1)
else:
  print(indx)

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

using namespace std;

const int MOD = 1000000007;
const int MAX32 = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  long long n, a, sum = 0, maxim = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    maxim = max(a, maxim);
    sum += maxim - a;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define re register
#define ll long long
using namespace std;
inline int read(){
	int k=1,sum=0;
	char c=getchar();
	for(;c<'0' || c>'9';c=getchar()) if(c=='-') k=-1;
	for(;c>='0' && c<='9';c=getchar()) sum=sum*10+c-48;
	return sum*k;
}
string s;
ll sum[20];
ll ans;
int n;
bool vis[20];
inline ll calc(){
	ll sum=0,res=0;
	for(re int i=0;i<n-1;++i){
		sum=sum*10+s[i];
		if(vis[i]) {res+=sum;sum=0;}
	}
	sum=sum*10+s[n-1];
	return res+sum;
}
inline void dfs(int x){
	if(x==n-1) {ans+=calc();return;}
	vis[x]=1;
	dfs(x+1);
	vis[x]=0;
	dfs(x+1);
}
int main(){
	cin>>s;n=s.length();
	for(re int i=0;i<n;++i) s[i]-='0';
	dfs(0);
	cout<<ans;
	return 0;
}
/*
6 3
2 3
1 2 
1 4 
4 5 
4 6 
0 2 5 1 2 3 
1 5 
1 3 
2 6 
*/

Measured memory_bytes: 256
"""
縦横300以下なので全探索できそう
まず横を切ることを考える
次に縦を切る

3/41にWAが出てしまったが一応できた。

"""

import numpy as np

H, W, K = map(int, input().split())

A = np.array([list(input()) for _ in range(H)])
ans = np.array([[0] * W for _ in range(H)])

k = 0
n = 1
c = 0

# まず横に切る
for i in range(H):
    if "#" not in A[i]:
        ans[i] = ans[i-1]
    else:
        NP = A[k:i+1,]
        for j in range(W):        
            if "#" not in NP[:,j]:
                ans[k:i+1,j] = n
            else:
                c += 1
                if c >= 2:
                    n += 1
                    c = 1
                ans[k:i+1,j] = n
        c = 0
        n += 1
        k = i + 1

# if "#" not in A[H-1]:
#     ans[H-1] = ans[H-2]

for i in ans:
    print(*i, sep=" ")

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

int main(){
    int ans,x,y;
    stack<int> stack;
    string s;
    while(cin>>s){
        if(s == "+"){
            x = stack.top(); 
            stack.pop();
            y = stack.top();
            stack.pop(); 
            stack.push(x+y);
        }
        if(s == "-"){
            x = stack.top(); 
            stack.pop();
            y = stack.top();
            stack.pop(); 
            stack.push(y-x);
        }
        if(s == "*"){    
            x = stack.top(); 
            stack.pop();
            y = stack.top();
            stack.pop(); 
            stack.push(x*y);
        }
        if(s!="+"&&s!="-"&&s!="*") stack.push(std::stoi(s));
        if(getchar()=='\n'){
      cout << stack.top() << endl;
      return 0;
    }
    }
}


Measured memory_bytes: 3192
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var a = make([]int, 5)
    for i:=0; i<5; i++{
        fmt.Scan(&a[i])
    }
    var k int
    fmt.Scan(&k)
    sort.Ints(a)
    ans := ":("
    if a[4]-a[0]<=k{
        ans = "Yay!"
    }
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func SortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}


Measured memory_bytes: 640
def p_c():
    n = int(input())
    H = list(map(int, input().split()))

    H.reverse()

    bf = 10 ** 9

    for h in H:
        if bf >= h:
            bf = h
        elif bf + 1 == h:
            pass
        else:
            print("No")
            exit()

    print("Yes")
    
p_c()

Measured memory_bytes: 63856
#include<cstdio>
#include<cmath>
using namespace std;
bool book[1000000];
int search[1000000];
int main()
{
	int n,x=0;
	
	int m=floor(sqrt(999999)+0.5);
	for(int i=2;i<=m;i++)
	{
		if(book[i]==false)
		{
			search[i]=++x;
			for(int j=2*i;j<=999999;j+=i)
				book[j]=true;
		}
		else
			search[i]=x;
	}
	for(int i=m+1;i<=999999;i++)
	{
		if(book[i]==false)
			search[i]=++x;
		else
			search[i]=x;
	}
	
	while(~scanf("%d",&n))
	{
		printf("%d\n",search[n]);
	}
	return 0;
}


Measured memory_bytes: 7460
Z = [0,1,2,3,4,5,6,7,8,9,10]
C = [0,1,2,3,4,5,6,7,8,9]
X = [0,1,2,3,4,5,6,7,8,9]

def solve_dp(s):
    n = len(s)
    s = [int(c) for c in s]
    inf = 10**9

    dp = [[inf] * 2 for _ in range(n)]

    d0 = s[0]
    dp[0][0] = Z[d0]
    dp[0][1] = Z[d0+1]

    for i in range(1, n):
        for j in range(2):
            d = s[i] + j
            for k in range(10):
                if d + C[k] >= 10:
                    dp[i][j] = min(dp[i][j], dp[i-1][1] + X[k] + Z[d + C[k] - 10])
                else:
                    dp[i][j] = min(dp[i][j], dp[i-1][0] + X[k] + Z[d + C[k]])

    return dp[n-1][0]

if __name__ == '__main__':
    s = input()
    s = "0"+ s
    print(solve_dp(s))

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

#define endl '\n'

using namespace std;

int N,M;

vector<int>node[100001];

int dp[100001];

int ans(int i){

  if(dp[i]!=-1){
    return dp[i];
  }
  
  int maxx=0;
  
  for(int j=0;j<node[i].size();j++){
    maxx=max(ans(node[i][j])+1,maxx);
  }

  return dp[i]=maxx;

}

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  memset(dp,-1,sizeof(dp));
  
  cin>>N>>M;

  int x,y;
  
  for(int i=0;i<M;i++){

    cin>>x>>y;

    node[x].push_back(y);
    
  }

  int maxx=0;
  
  for(int i=1;i<=N;i++){
    maxx=max(ans(i),maxx);
  }

  cout<<maxx<<endl;
  
  return 0;

}


Measured memory_bytes: 8192
#include <iostream>
#include <cmath>
using namespace std;
int main() {
  long long n;
  while(cin >> n) {
    if (n%2)
      cout << 2*(long long)pow(3,(n+1)/2)/3-1 << endl;
    else
      cout << (long long)pow(3,n/2)-1 << endl;
  }
}

Measured memory_bytes: 0
#include<stdio.h>
#define MAX 100

int adj[MAX][MAX];
int d[MAX];
int f[MAX];
int flg[MAX];
int time=0;

void dfs(int u,int n){
	
	flg[u]=1;
	d[u]=++time;
	
	for(int i=0;i<n;i++){
		if(adj[u][i] && !flg[i]){
			dfs(i,n);
		}
	}
	f[u]=++time;
	
	return;
	
}

int main(){
	int n,i,j;
	int x,y,z;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		flg[i]=0;
		for(j=0;j<n;j++)
			adj[i][j]=0;
	}
	
	for(i=0;i<n;i++){
		scanf("%d %d",&x,&y);
		for(j=0;j<y;j++){
			scanf("%d",&z);
			adj[x-1][z-1]=1;
		}
	}
	
	for(i=0;i<n;i++){
		if(!flg[i])
			dfs(i,n);
	}
	
	for(i=0;i<n;i++)
		printf("%d %d %d\n",i+1,d[i],f[i]);
	
	return 0;
	
}


Measured memory_bytes: 2052
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    
    ll b;
    while(cin >> b,b){
        ll ans1 = b , ans2 = 1;
        ll c = 2;
        while(2*b > c*c - c){
            if((2*b-(c*c-c))%(2*c) == 0){
                ans1 = min(ans1,(2*b-(c*c-c))/(2*c));
                ans2 = c;
            }
            c++;
        }
        cout << ans1 << " " << ans2 << endl;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    //cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}



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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	if (N == M) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	static Scanner sc = new Scanner( System.in );
	
	static int n, s, count;
	static boolean num[] = new boolean[10];
	
	public static void main(String[] args) {
		
		while ( read() ) {
			count = 0;
			solve(0, 0, 0);
			System.out.println( count );
		}
	}
	
	public static boolean read() {
		
		n = sc.nextInt();
		s = sc.nextInt();
		
		if ( n == 0 && s == 0 ) {
			return false;
		}
		
		return true;
	}
	
	public static void solve( int select, int current, int sum ) {

		if ( select != n ) {
			while ( current < 10 ) {
				solve( select + 1, current + 1, sum + current );
				
				current++;
			}
		} else {
			if ( s == sum ) {
				count++;
			}
		}
		
	}

}

Measured memory_bytes: 18160
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int N;
    std::cin >> N;
    std::vector<int> v(N);
    for (auto& e : v) std::cin >> e;

    int Q;
    std::cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int k;
        std::cin >> k;
        std::cout << (std::lower_bound(v.begin(), v.end(), k) - v.begin()) << " "
                  << (std::upper_bound(v.begin(), v.end(), k) - v.begin()) << std::endl;
    }
}



Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
#include <numeric>
#include <type_traits>

using namespace std;

int main() {
	string s;
	cin >> s;

	sort(s.begin(), s.end());
	if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(0) != s.at(2)) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <deque>
#include <vector>

typedef long long ll;
using namespace std;

#define FOR(i, a, b) for (int i = a; i <= b; ++ i)
#define rep(i, a) FOR(i, 0, a)

int main(){
  ll n, m;
  cin >> n >> m ;
  if( m/2 <= n){
    cout << m/2 << endl;
  } else {
    cout << n + (m - 2 * n)/4 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
awk 'function abs(x){return x<0?-x:x}
function min(x,y){return x<y?x:y}
{
  s = $1
  n = length(s)
  ans = 10000
  for(i=1; i<=n-2; ++i) {
      x = int(substr(s,i,1) substr(s,i+1,1) substr(s,i+2,1))
      ans=min(ans,abs(x-753))
      if (abs(x-753)==23)print x
    }
  print ans
}'


Measured memory_bytes: 552
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var fs = new List<KeyValuePair<long, int>>();
            for(long i=2;i*i<=N;i++)
            {
                var x = 0;
                while(N%i==0)
                {
                    N /= i;
                    x++;
                }
                fs.Add(new KeyValuePair<long, int>(i, x));
            }
            if (N != 1) fs.Add(new KeyValuePair<long, int>(N, 1));

            var ans = 0;
            foreach(var p in fs)
            {
                var x = p.Value;
                var b = 1;
                while(b<=x)
                {
                    x -= b;
                    b++;
                    ans++;
                }
            }
            WriteLine(ans);
        }

    }
}


Measured memory_bytes: 60616
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int yaaa[10];
	for(int i=0;i<10;i++){
		cin >> yaaa[i];
	}
	sort(&yaaa[0],&yaaa[10]);
	for(int i=0;i<3;i++){
	cout <<yaaa[9-i]<<endl;
}
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  n %= 100;
  n %= 10;
  if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9){
    cout << "hon" << endl;
  }
  else if(n == 0 || n == 1 || n == 6 || n == 8){
    cout << "pon" << endl;
  }
  else if(n == 3){
    cout << "bon" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>

int main() {
  int n;
  std::cin >> n;
  int64_t ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 != 0 && i % 5 != 0) {
      ans += i;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 3636
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N = int(readline())

D = list(map(int,readline().split()))
cnt = [0]*13
for d in D:
    cnt[min(24-d,d)] += 1
cnt[0] += 1
for i in range(1,12):
    if cnt[i] >= 3:
        print(0)
        exit()
if cnt[0] >= 2 or cnt[12] >= 2:
    print(0)
    exit()

where = [0]*24
where[0] = 1
b = 0
if cnt[12]:
    where[12] = 1
for i in range(1,12):
    c = cnt[i]
    if c == 0:
        continue
    if c == 2:
        where[i] = 1
        where[24-i] = 1
        b = 0
    else:
        if b:
            where[i] = 1
            b = 0
        else:
            where[24-i] = 1
            b = 1

ans = INF
a = 1
for i in range(1,24):
    if where[i]:
        ans = min(ans,a)
        a = 1
    else:
        a += 1
ans = min(ans,a)
print(ans)



Measured memory_bytes: 9480
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	long int n,temp,pos,max,max2;
  cin>>n;
  cin>>temp;
  max=temp;
  cin>>temp;
  max2=temp;
  
  pos=0;
  
  if(max2>max)
  {
    max2=max;
    max=temp;
    pos=1;
  }
  
  for(long int i=2;i<n;i++)
  {
    cin>>temp;
    if(temp>max)
    {
      max2=max;
      max=temp;
      pos=i;
    }
    else if(temp>max2)
      max2=temp;
  }
  
  for(long int i=0;i<n;i++)
  {
    if(pos==i)
      cout<<max2<<endl;
    else
      cout<<max<<endl;
  }
  return 0;
}

Measured memory_bytes: 1664