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

using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
struct things{
    long long a,b;
};
int n,m;
long long d[101][100001];
things a[101];
long long kq;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i].a>>a[i].b;
    for(int i=0;i<=n;i++)
    {
        for(int j=1;j<=100000;j++)
            d[i][j]=INT_MAX;
    }
    d[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=100000;j++)
        {
            d[i][j]=d[i-1][j];
            if(d[i][j]<=m)
                kq=max(kq,(long long)j);
            if(j<a[i].b)
                continue;
            d[i][j]=min(d[i][j],d[i-1][j-a[i].b]+a[i].a);
            if(d[i][j]<=m)
                kq=max(kq,(long long)j);
        }
    }
    cout<<kq;
    return 0;
}


Measured memory_bytes: 79232
// -*- coding: utf-8 -*-
// @Date    : 2019-11-09 18:32:56

#include <bits/stdc++.h>
#define greeting cerr << "What's your problem?\n"

using namespace std;
typedef long long ll;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v)
{
	for(auto i : v)
		os << i << " ";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& v)
{
	for(auto i : v)
		os << i << " ";
	return os;
}

#define locala
int main()
{
#ifdef local
	freopen("data.in", "r", stdin);
	freopen("ans.out", "w", stdout);
#endif	
	ll n;
	scanf("%lld", &n);
	for(ll i = sqrt(n); i; --i)
		if(n % i == 0)
			return 0*printf("%lld\n", n/i+i-2);
	printf("%lld\n", n-1);
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
string s;
bool b[1000];
ll ans=0;
bool check(char c){
	return ((c=='A')||(c=='C')||(c=='G')||(c=='T'));
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>s;int n=s.size();
	for(int i=0;i<n;i++)b[i]=check(s[i]);//cout<<b[i];cout<<'\n';
	for(int i=0;i<n;i++)if(b[i]){
		ll cnt=1;
		for(int j=i+1;j<n;j++){
			if(b[j]==1)cnt++;
			else break;
		}
//		cout<<cnt;
		ans=max(ans,cnt);
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repbit(bit,n) for (int bit = 0; bit < (1<<n); bit++)
using namespace std;
typedef long long ll;

const int INF = 1001001001;
//const ll INF = 1000000000000000000;

ll a, b, v, w, t;

int main() {
	int x, n;
	cin >> x >> n;

	vector<bool> contain(102, false);
	rep(i,n) {
		int p;
		cin >> p;
		if (!contain[p]) contain[p] = true;
	}
	int ans, tmp = INF;
	for (int i = 101; i >= 0; i--) {
		if (!contain[i]) {
			if (tmp >= abs(i - x)) {
				tmp = abs(i - x);
				ans = i;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(void){
    int N;
    cin>>N;
    char a[N];
    char b[N];
    int d;
    d=N*2;
    char c[d];
    for(int i=0;i<N;i++){
        cin>>a[i];
        c[2*i]=a[i];
    }
     for(int j=0;j<N;j++){
        cin>>b[j];
        c[2*j+1]=b[j];
    }
    for(int j=0;j<d;j++){
        cout<<c[j];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N = 100;
  int A, B;
  cin >> A >> B;
  A--; B--;
  swap(A,B);
  vector<vector<char>> ans(N,vector<char>(N));
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(i < 50){
        ans[i][j] = '.';
      }
      else{
        ans[i][j] = '#';
      }
    }
  }
  
  
  for(int i=0; i<N; i++){
    bool end = false;
    for(int j=0; j<N; j++){
      if(A == 0){
        end = true;
        break;
      }
      if(i %2 == 0 && j %2 == 0){
        ans[i][j] = '#';
        A--;
      }
    }
    if(end){
      break;
    }
  }
  
  for(int i=0; i<N; i++){
    bool end = false;
    for(int j=0; j<N; j++){
      if(B == 0){
        end = true;
        break;
      }
      if(i %2 == 0 && j %2 == 0){
        ans[99-i][j] = '.';
        B--;
      }
    }
    if(end){
      break;
    }
  }
  
  cout << 100 << " " << 100 << endl; 
  
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      cout << ans[i][j];
    }
    cout << endl;
  }
      
}

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

#define MOD 1000000007

LL dp[2][400][400];
LL sums[400][400];

LL nshared[400][400];
LL ok[400];
int main(){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int posa[n];
    int posb[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
        posa[a[i]] = i;
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
        b[i]--;
        posb[b[i]] = i;
    }
    int k = n/3;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            nshared[i][j] = 0;
            for(int c = 0; c < n; c++){
                ok[c] = 0;
            }
            for(int c = i; c < n; c++) ok[a[c]]++;
            for(int c = j; c < n; c++) ok[b[c]]++;
            for(int c = 0; c < n; c++){
                if(ok[c] == 2){
                    nshared[i][j]++;
                }
            }
        }
    }
    dp[0][n][n] = 1;
    for(int c = 1; c <= k; c++){
        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= n; j++){
                dp[c%2][i][j] = 0;
                sums[i][j] = 0;
            }
        }
        for(int i = n; i >= 0; i--){
            for(int j = n; j >= 0; j--){
                if(j < n) sums[i][j] += sums[i][j+1];
                if(i < n) sums[i][j] += sums[i+1][j];
                if(i < n && j < n) sums[i][j] -= sums[i+1][j+1];

                sums[i][j] += dp[1-c%2][i][j];

                sums[i][j] %= MOD;
                while(sums[i][j] < 0) sums[i][j] += MOD;
                //cout << sums[i][j] << " ";
            }
            //cout << endl;
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(a[i] == b[j]) continue;
                if(nshared[i][j] != nshared[i+1][j+1] + 2){
                    continue;
                }
                LL npairs = nshared[i][j] - (3*c-1);
                if(npairs <= 0) continue;
                dp[c%2][i][j] = (sums[i+1][j+1] * npairs) % MOD;
            }
        }
    }
    LL f = dp[k%2][0][0];
    f %= MOD;
    while(k > 0){
        f = (f * (3*k-1)) % MOD;
        f = (f * (3*k-2)) % MOD;
        k--;
    }
    while(f < 0) f += MOD;
    cout << f << endl;
}


Measured memory_bytes: 5248
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MAX = 2 * 10 ** 5 + 5
MOD = 10 ** 9 + 7

fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]

def comInit(mod):
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

def com(mod, n, k):
    numerator = 1
    for i in range(1, k + 1):
        numerator *= (n - i + 1)
        numerator %= mod
    return (numerator * finv[k] % mod)
comInit(MOD)

n, a, b = map(int, readline().split())
nb = n
x = 2
y = 1
while n > 1:
    if n % 2 == 1:
        y *= x
        n -= 1
    else:
        x *= x
        n //= 2
    x %= MOD
    y %= MOD
ans = (x * y % MOD) - 1
print((ans - com(MOD, nb, a) - com(MOD, nb, b)) % MOD)

Measured memory_bytes: 27268
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<(int)c;++i)
int main(){
   string s;
   cin >> s;
   for(int i= 0;i<s.size();i++){
       if(count(s.begin(),s.end(),s[i])%2!=0){
           cout << "No" <<endl;
           return 0;
       }
   }
   cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<algorithm>
using namespace std;

string sa,sb;
map<string,int> m1;

int main(){
	int n,m;
	int a,b,c;
	int i,j,k;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>sa;
		a=0;
		m=sa.size(),sb=sa;
		m1.clear();
		for(j=1;j<m;j++){
			for(k=0;k<8;k++){
				sb=sa;
				if((k/2)%2)reverse(sb.begin(),sb.begin()+j);
				if(k%2)reverse(sb.begin()+j,sb.end());
				if(k<4)sb=sb.substr(j,m-j)+sb.substr(0,j);
				if(m1.find(sb)==m1.end()){
					a++;
					m1[sb]=1;
				}
			}
		}
		//for(auto itr=m1.begin();itr!=m1.end();itr++){
			//cout<<itr->first<<endl;
		//}
		cout<<a<<endl;
	}
}
			



Measured memory_bytes: 3244
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>

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

	std::vector<int> a(N);
	for (int i = 0; i < N; ++i) {
		std::cin >> a[i];
		if ((a[i] % 2) == 0) {
			if (((a[i] % 3) != 0) && ((a[i] % 5) != 0)) {
				std::cout << "DENIED";
				return 0;
			}
		}
	}
	
	std::cout << "APPROVED";
	return 0;
}

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

bool is_integer(double x) {
    return std::floor(x)==x;
}

int main(){
    int ans(0);
    char c[3];
    rep(i,3){
        cin >> c[i];
        if(c[i]=='R')
            ans++;
    }

    if(ans==2&&c[1]=='S'){
        cout << 1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();
  vector<ll> a(N);
  REP(i, N) a[i] = nextLong();
  ll ans = 0;
  ll highest = -1;
  REP(i, N) {
    if (a[i] > highest) {
      highest = a[i];
    } else {
      ans += highest - a[i];
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e10;
const int MOD = 1e9+7;

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

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    vs s(N); REP(i, N) cin >> s[i];

    int ans = 0;
    int a = 0, b = 0, c = 0;
    REP(i, N)
    {
        REP(j, s[i].length()-1)
        {
            if(s[i][j] == 'A' && s[i][j+1] == 'B') ans++;
        }
        if(s[i][0] == 'B' && s[i][s[i].length()-1] == 'A') c++;
        else if(s[i][0] == 'B') b++;
        else if(s[i][s[i].length()-1] == 'A') a++;
    }
    if(c == 0) cout << ans + min(a, b) << endl;
    else if(a == 0 && b == 0) cout << ans + c-1 << endl;
    else cout << ans + c + min(a, b) << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int N;
int a[200000];
int t[200000];

bool f(int s) {
  for (int i=0; i<2*N-1; i++) t[i] = a[i] >= s ? 1 : 0;

  int g = N-1;
  if (t[g] == t[g-1] || t[g] == t[g+1]) return t[g];
  int l = t[g-1];
  int r = t[g+1];
  for (int i=2; i<N; i++) {
    if (t[g-i] == l) {
      return i < N ? l : (t[g] + N + 1) % 2;
    }
    if (t[g+i] == r) {
      return i < N ? r : (t[g] + N + 1) % 2;
    }
    l = t[g-i];
    r = t[g+i];
  }
  return (t[g] + N + 1) % 2;
}

int main() {
  cin >> N;
  for (int i=0; i<2*N-1; i++) cin >> a[i];
  if (N == 2) {
    cout << "2\n";
  }
  else {
    int lo = 1, hi = 2*N-1;
    int mid;
    while (lo != hi) {
      mid = (lo + hi) / 2;
      if (f(mid)) {
        if (f(mid + 1)) lo = mid + 1;
        else {
          lo = mid;
          break;
        }
      }
      else hi = mid - 1;
    }
    cout << lo << "\n";
  }
  return 0;
}



Measured memory_bytes: 1920
#include "bits/stdc++.h"
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	string S; cin>>S;

	if(S[a] != '-'){
			cout<< "No" <<endl;
			return 0;
		}
	for(int i=0;i<a+b+1;i++){
		if(i==a)continue;
		if(S[i] < '0' || '9' < S[i]){
			cout<< "No" <<endl;
			return 0;
		}
	}
	cout<< "Yes" <<endl;

	return 0;
}

Measured memory_bytes: 256
[n, m, l] = [int(x) for x in raw_input().split()]

A = []
B = []
counter = 0
while counter < n:
    A.append([int(x) for x in raw_input().split()])
    counter += 1

counter = 0
while counter < m:
    B.append([int(x) for x in raw_input().split()])
    counter += 1

B = list(zip(*B))

for i in range(n):
        print(' '.join([str(x) for x in [sum([x[0] * x[1] for x in zip(A[i], B[j])]) for j in range(l)]]))

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

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define bg begin()
#define ed end()
#define pii pair<int,int>

int main()
{
	int n,k;
	while(cin >> n >> k){
		int num=n/2+(n&1);
		if(num>=k){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	}
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func f(b, n int) int {
	if n < b {
		return n
	}
	return f(b, n/b) + n%b
}

func solve(n, s int) int {
	if n < s {
		return -1
	}
	// } else if n == s {
	if n == s {
		return n + 1
	}
	for i := 2; i*i <= n; i++ {
		if f(i, n) == s {
			return i
		}
	}
	for i := int(math.Sqrt(float64(n))); i > 0; i-- {
		if (n-s)%i == 0 && f((n-s)/i+1, n) == s {
			return (n-s)/i + 1
		}
	}
	return -1
}

func main() {
	scn := newScanner()
	n := scn.nextInt()
	s := scn.nextInt()
	fmt.Println(solve(n, s))
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) nextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) nextInt() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) nextInt64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(d)]
t = [int(input()) for i in range(d)]
mem = [0 for i in range(26)]
v = 0
su = sum(c)
for a in range(d):
    v += s[a][t[a]-1]
    mem[t[a]-1] = a+1
    for i in range(26):
        v -= c[i]*(a+1 - mem[i])
    print(v)

Measured memory_bytes: 68420
#include <bits/stdc++.h>
/*    #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;       */
using namespace std;

#define ll long long
#define ull unsigned long long
#define f(a, b) for (ll i = a; i < b; i++)
#define mod 1000000007
#define pb push_back
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define ld long double
#define fr(a, b) for (ll j = a; j >= b; j--)
#define fi(a, b) for (ll j = a; j < b; j++)
#define fii(a, b) for (ll k = a; k < b; k++)
//      typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

template <class T>
ostream &operator<<(ostream &os, vector<T> V)
{
    os << "[ ";
    for (auto v : V)
        os << v << " ";
    os << "]";
    return os;
}
template <class T>
ostream &operator<<(ostream &os, set<T> S)
{
    os << "{ ";
    for (auto s : S)
        os << s << " ";
    return os << "}";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P)
{
    return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R>
ostream &operator<<(ostream &os, map<L, R> M)
{
    os << "{ ";
    for (auto m : M)
        os << "(" << m.first << ":" << m.second << ") ";
    return os << "}";
}

struct sol
{
    ll x, prev;
    sol(ll xx, ll pr)
    {
        x = xx;
        prev = pr;
    }
    ll valAt(ll k)
    {
        ll d = k - x;
        return d * d + prev;
    }
    double intersect(sol s1)
    {
        double k = double(x * x) * 1.0 - double(s1.x * s1.x) * 1.0;
        k += prev * 1.0 - s1.prev * 1.0;
        k /= 2.0;
        k /= (x - s1.x) * 1.0;
        return k;
    }
};

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

    ll n, c, ans = 0;
    cin >> n >> c;
    deque<sol> q;
    f(0, n)
    {
        ll x;
        cin >> x;
        while (q.size() >= 2 && q[0].valAt(x) >= q[1].valAt(x))
            q.pop_front();
        if (q.size() > 0)
            ans = q[0].valAt(x);
        sol s1 = sol(x, ans + c);
        while (q.size() >= 2 && q[q.size() - 2].intersect(q[q.size() - 1]) > q[q.size() - 2].intersect(s1))
            q.pop_back();
        q.push_back(s1);
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 2432
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def bfs(table,memo)
  que = [[rand(table.size),1]]
  ans = 0
  while que.size > 0
    i,t = que.shift
    next if(memo[i] != 0)
    ans = t
    memo[i] = t
    table[i].each do |d|
      if(memo[d] != 0 and memo[d] != (t -1))
        return -1
      end
      que.push([d,t+1])
    end
  end
  return ans
end

n = inp[0]
table = na2(n,0)
memo = na(n,0)
n.times do |i|
  s = inps[0]
  s.split("").map(&:to_i).each.with_index do |d,j|
    table[i].push(j) if(d == 1)
  end
end
t = Time.now
ans = -1
while Time.now - t < 1.9
  ans = [bfs(table,memo),ans].max
  memo = na(n,0)
end
p ans


Measured memory_bytes: 3388
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <numeric>

using namespace std;

const int N = 100101;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n; cin >> n;
  cout << (n == 7 || n == 5 || n == 3 ? "YES": "NO") << endl;
}


Measured memory_bytes: 256
a, b, c = gets.split.map(&:to_i)
w = 7 * a + b
n = [c / w - 1, 0].max
c -= w * n
k = 7 * n
until c <= 0
  c -= a
  k += 1
  c -= b if k % 7 == 0
end
p k



Measured memory_bytes: 6872
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

int memo[510][510][2];
struct aa {
	int nx;
	int ny;
};
int main() {
	while (1) {
		for (int i = 0; i < 510; ++i) {
			for (int j = 0; j < 510; ++j) {
				for (int k = 0; k < 2; ++k) {
					memo[i][j][k] = 0;
				}
			}
		}
		int H, W, R, C; cin >> H >> W >> R >> C;
		if (!H)break;
		vector<vector<vector<int>>>walls(H+4, vector<vector<int>>(W+4, vector<int>(4,3)));
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				int a; cin >> a;
				walls[i + 1][j+2][1] = a;
				walls[i + 2][j+2][3] = a;
			}
			for (int j = 0; j < W + 1; ++j) {
				int a; cin >> a;
				walls[i + 2][j + 1][2] = a;
				walls[i + 2][j + 2][0] = a;
			}
		}
		for (int j = 0; j < W; ++j) {
			int a; cin >> a;
			walls[H + 1][j + 2][1] = a;
			walls[H + 2][j + 2][3] = a;
		}
		queue<aa>que;
		for (int t = 0; t < 2; ++t) {
			for (int y = 2; y < H + 2; ++y) {
				que.push(aa{ 1,y });
				memo[y][1][t] = true;
				que.push(aa{ W + 2,y });
				memo[y][W + 2][t] = true;
			}
			for (int x = 2; x < W + 2; ++x) {
				que.push(aa{ x,1 });
				memo[1][x][t] = true;
				que.push(aa{ x,H + 2 });
				memo[H + 2][x][t] = true;
			}
		}
		bool ok = false;
		vector<pair<int, int>>anss;
		anss.emplace_back(C+ 1, R + 1);
		for (int i = 0; i < 4; ++i) {
			if (!walls[R+ 1][C+ 1][i])anss.emplace_back(C +1+ dx[i], R + 1+ dy[i]);
		}
		vector<vector<int>>ws(H, vector<int>(W, false));
		while (!que.empty()) {
			aa atop(que.front());
			que.pop();
			const int nowx = atop.nx;
			const int nowy = atop.ny;
			if (find(anss.begin(), anss.end(), make_pair(nowx, nowy)) != anss.end()) {

				ok = true;
				//break;
			}
			for (int t = 0; t < 2; ++t) {
				for (int way = 0; way < 4; ++way) {
					if (walls[nowy][nowx][way] == 3)continue;
					if (!(walls[nowy][nowx][way] ^ t)) {
						const int nexty = nowy + dy[way];
						const int nextx = nowx + dx[way];
						if (!memo[nexty][nextx][t]) {
							memo[nexty][nextx][t] = true;
							if (memo[nexty][nextx][!t]) {
								que.push(aa{ nextx,nexty });
								ws[nexty - 2][nextx - 2] = true;
							}
						}
					}
				}
			}
			
			
		}
		/*cout << endl;
		cout << "cango" << endl;
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				cout << ws[i][j] << " ";
			}
			cout << endl;
		}
		cout << endl;*/
		if (ok)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	
	return 0;
}

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

#include <set>
#include <vector>
#include <numeric>

int main() {
    int n,z,w;
    cin >> n >> z >> w;
    vector <int> a(n);
    rep(i,n) cin >> a[i];
    if(n == 1){
        cout << abs(a[n-1]-w) << endl;
    }else{
        cout << max(abs(a[n-1]-w), abs(a[n-1]-a[n-2])) << endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int64 solve(int64 n) {
  if (n == 0) return 0;
  int64 ret = 0;
  for (int k = 0; k < 60; ++k) {
    int64 len = 1LL << (k + 1);
    int64 q = n / len, r = n % len;
    int64 cur = (1LL << k) * q;
    cur += max(0LL, r - (1LL << k));
    if (cur & 1) ret |= 1LL << k;
  }
  return ret;
}

int main() {
  int64 a, b;
  cin >> a >> b;
  int64 ret = solve(b + 1) ^ solve(a);
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env php
<?php

$inputs = [];
while (($item = fgets(STDIN)) !== false) {
    $inputs[] = $item;
}

$map = [
    'A' => 'T',
    'T' => 'A',
    'C' => 'G',
    'G' => 'C',
];
$x = trim(array_shift($inputs));
echo $map[$x].PHP_EOL;


Measured memory_bytes: 4728
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
   int n = sc.nextInt();
   int a;
   int[][] clue = new int[n][n];
   for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       clue[i][j] = -1; 
     }
   }
   for(int i = 0; i < n; i++){
     a = Integer.parseInt(sc.next());
     for(int j = 0; j < a; j++){
       clue[i][Integer.parseInt(sc.next()) - 1] = Integer.parseInt(sc.next());
     }
   }

   int honest;
   int max = 0;
   boolean bl;

   for(int i = 0; i < (1<<n); i++ ){
     bl = true;
     for(int j = 0; j < n; j++){

       honest = ((i >> j) & 1);//no problem
       if(honest == 1){
         for(int k = 0; k < n;k++){
           if(clue[j][k] != -1 && clue[j][k] != ((i >> k) & 1)){
             bl = false;
             break;
           }
         }
       }
       if(!bl){
         break;
       }
    }
    if(!bl){
      continue;
    }
    max = Math.max(max,Integer.bitCount(i));//problem
  }
  System.out.println(max);
}
}



Measured memory_bytes: 23124
import math
n=int(input())
x=[]
sum=0
for i in range(n):
    x.append(list(map(int,input().split())))
for i in range(n):
    for s in range(i+1,n):
        sum+=math.sqrt((x[i][0]-x[s][0])**2+(x[i][1]-x[s][1])**2)
sum=sum*2*(n-1)*math.factorial(n-2)/math.factorial(n)
print(sum)

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define dump(x)  cout << #x << " = " << (x) << endl;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
//             0123456789 - digits. check the limits, int vs long
const int MX = 100001;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if(i < 10) ans++;
        else if (i > 99 && i < 1000) ans++;
        else if (i > 9999 && i < 100000) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < ((int)b); ++i)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= ((int)a); --i)
#define sz(x) ((int)x.size())

using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

void dump_impl(string s) {}
template <class H, class... T>
void dump_impl(string s, H head, T... tail) {
    int p = 0;
    rep(i, 0, s.size()) {
        char x = s[i];
        if (p == 0 && x == ',') {
            cerr << " = " << head << ", ";
            dump_impl(s.substr(i + 1), tail...);
            return;
        } else {
            cerr << x;
            if (x == '(') p++;
            if (x == ')') p--;
        }
    }
}
#ifdef LOCAL
#define dump(...) do { cerr << "\x1b[33;1m"; dump_impl(#__VA_ARGS__ ",", __VA_ARGS__); cerr << "\x1b[0m" << endl; } while (0)
#else
#define dump(...)
#endif

const int INF = 1e9;

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

bool inrange(int x, int l, int r) {
    return l <= x && x < r;
}

const int DY[] = {-1, 0, 1, 0};
const int DX[] = {0, 1, 0, -1};

int rot(int dir, int type) {
    if (type == 0) return dir;
    if (type == 1) return (dir + 1) % 4;
    if (type == 2) return (dir + 2) % 4;
    if (type == 3) return (dir + 3) % 4;
    if (type == 4) return -1;
    assert(false);
}

void solve(int W, int H) {
    vvi B(H, vi(W));
    rep(i, 0, H) rep(j, 0, W) cin >> B[i][j];
    vi C(5);
    rep(i, 0, 4) cin >> C[i];
    C[4] = 0;

    vector<vvi> dist(H, vvi(W, vi(4, INF)));
    dist[0][0][1] = 0;
    using dijkstra_state = tuple<int, int, int, int>;
    priority_queue<dijkstra_state, vector<dijkstra_state>, greater<>> pq;
    pq.push(dijkstra_state(0, 0, 0, 1));
    while (sz(pq)) {
        int cur_dist, y, x, dir;
        tie(cur_dist, y, x, dir) = pq.top(); pq.pop();
        if (cur_dist > dist[y][x][dir]) continue;
        rep(r, 0, 5) {
            int dd = (r < 4 ? rot(dir, r) : rot(dir, B[y][x]));
            if (dd == -1) {
                continue;
            }
            int yy = y + DY[dd];
            int xx = x + DX[dd];
            if (inrange(yy, 0, H) && inrange(xx, 0, W)) {
                if (chmin(dist[yy][xx][dd], dist[y][x][dir] + C[r])) {
                    pq.push(dijkstra_state(dist[yy][xx][dd], yy, xx, dd));
                }
            }
        }
    }

    int ans = INF;
    rep(i, 0, 4) chmin(ans, dist[H - 1][W - 1][i]);
    cout << ans << endl;
}

signed main() {
    while (1) {
        int W, H;
        cin >> W >> H;
        if (W == 0 && H == 0) break;
        solve(W, H);
    }
}


Measured memory_bytes: 3408
function main(input) {
  var answer = 0;
  var input = input.split('\n');
  var str_input = input[0];
  for (var j = 0; j < str_input.length; j++) {
    var str_number = str_input[j];
    if(str_number != '1'){
      answer = str_input[j];
      break;
    } else if(j + 1 == input[1]){
      answer = 1;
      break;
    }
  }
 
  console.log(parseInt(answer));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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



int main()
{
        int n;
        cin>>n;
        LL a[n+2],DP[n+2];
        for(int i=1;i<=n;i++)
        {
                cin>>a[i];
                DP[i]=1e12;
        }
        DP[1]=0;
        for(int i=1;i<=n-1;i++)
        {
                DP[i+1]=min(DP[i+1],DP[i]+abs(a[i+1]-a[i]));
                if(i==n-1) continue;
                DP[i+2] = min(DP[i+2] , DP[i]+abs(a[i+2] - a[i]));
        }
        cout<<DP[n]<<endl;
  }

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define MP make_pair
#define FOR(i,a,b) for(int i=a;i<b;++i)

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

int main(){

  int n, m;
  bool f[200001]={};
  vector<int> v;

  scanf("%d %d", &n, &m);
  REP(i,m){
    int t1, t2;
    scanf("%d %d", &t1, &t2);
    if(t1 == 1){
      f[t2] = true;
    }else if(t2 == n){
      v.pb(t1);
    }
  }

  REPI(itr,v){
    if(f[*itr]){
      printf("POSSIBLE\n");
      return 0;
    }
  }

  printf("IMPOSSIBLE\n");

  return 0;
}



Measured memory_bytes: 1020
#include <iostream>

using namespace std;

int main() {

	int K, A, B;
	cin >> K >> A >> B;

	int i = 1;

	while (K*i <= B)
	{
		if (A<=K * i && B>=K * i) {
			cout << "OK" << endl;
			return 0;
		}
		i++;
	}

	cout << "NG" << endl;

	return 0;
}

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

int main(void)
{
    int n,l;
    char s[110][110];
    scanf("%d%d", &n, &l);
    for(int i=0;i<n;i++) scanf("%s", s[i]);
    qsort(s,n,sizeof(s[0]),strcmp);
    for(int i=0;i<n;i++) printf("%s",s[i]);
    printf("\n");
    return 0;
}


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

#define repi(i, s, n) for (ll i {s}; i##_len{n}; i < i##_len; ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

namespace forno
{
template<typename T>
T get_value(std::istream& is);
template<typename T>
T input();
template<typename C>
void container_fill(C& c, std::istream& is);
template<typename C>
void inputfill(C& c);
template<typename C>
ll llsize(const C& c);
template<typename C, size_t N>
ll llsize(const C(&)[N]);

ll llgcd(ll a, ll b);
ll lllcm(ll a, ll b);
ll lllog2(ll x);
}
using namespace forno;

int main()
{
  vector<int> a(input<int>());
  auto m {input<int>()};
  inputfill(a);
  {
    const auto t {lllog2(a[0])};
    for (auto& e: a) {
      if (t != lllog2(e)) {
        cout << "0\n";
        return 0;
      }
      if (e % 2) {
        cout << "0\n";
        return 0;
      }
      e >>= 1;
    }
  }

  ll l {1};
  for (auto e: a)
    l = lllcm(l, e);
  if (l > m) {
    cout << "0\n";
    return 0;
  }

  auto res {m / l};
  cout << (res + 1) / 2 << '\n';

  return 0;
}

class initalization
{
  class custom_numpunct: public std::numpunct<char>
  {
  public:
    using numpunct::numpunct;
  protected:
    std::string do_truename() const override { return "Yes"; }
    std::string do_falsename() const override { return "No"; }
  };

public:
  initalization()
  {
    std::cin.sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout << std::boolalpha;
    std::cout.imbue(std::locale(std::cout.getloc(), new custom_numpunct{}));
  }
} initalize;

namespace forno
{

template<typename T>
T get_value(std::istream& is)
{
  T v;
  is >> v;
  return v;
}

template<typename T>
T input()
{
  return get_value<T>(std::cin);
}

template<typename C>
void container_fill(C& c, std::istream& is)
{
  for (auto& e: c)
    is >> e;
}

template<typename C>
void inputfill(C& c)
{
  container_fill(c, std::cin);
}

template<typename C>
ll llsize(const C& c)
{
  return static_cast<ll>(c.size());
}

template<typename C, size_t N>
ll llsize(const C(&)[N])
{
  return static_cast<ll>(N);
}

ll llgcd(ll a, ll b)
{
  return b ? llgcd(b, a%b) : a;
}

ll lllcm(ll a, ll b)
{
  return a / llgcd(a, b) * b;
}

ll lllog2(ll x)
{
  ll res {0};
  for (;!(x % 2); ++res)
    x >>= 1;
  return res;
}

}


Measured memory_bytes: 640
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

sx,sy,tx,ty=get_i
ans=""
dx=tx-sx
dy=ty-sy
dx.times do
    ans+="R"
end
dy.times do
    ans+="U"
end
dx.times do
    ans+="L"
end
dy.times do
    ans+="D"
end
ans+="D"
(dx+1).times do
  ans+="R"
end
(dy+1).times do
    ans+="U"
end
ans+="L"
ans+="U"
(dx+1).times do
  ans+="L" 
end
(dy+1).times do
    ans+="D"
end
ans+="R"
puts ans

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

const ll mod=1000000007;

int ret=0;
vector<int> vi;

int bfs(const Graph& g,int i){
    vi[i]=1;
    for(auto next:g[i]){
        if(vi[next]!=0)continue;
        ret=bfs(g,next)+1;
    }
    return ret;
} 

int main(){
    int n,m;
    cin>>n>>m;
    Graph G(n);
    vi.assign(n,0);
    set<P> s;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        P p(a,b);
        P q(b,a);
        if(!s.count(p)&&!s.count(q)){
            G[a].push_back(b);
            G[b].push_back(a);
            s.insert(p);
            s.insert(q);
        }
    }
    int ans=bfs(G,0);
    ret=0;
    rep(i,n){
        if(vi[i]!=0)continue;
        ans=max(ans,bfs(G,i));
        ret=0;
    }
    cout<<ans+1<<endl;

}

Measured memory_bytes: 39864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 301000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
//union_find
int n,k,l;
int p,q,r,s;

class UnionFind{
    int par[MAX];
    int depth[MAX];
    public:
    UnionFind(){
        for(int i = 1; i < MAX; i++){
            par[i] = i;
            depth[i] = 0;
        }
    }
    //find=root
    int find(int x){ 
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(depth[x] > depth[y]) par[y] = x;
        else {
            if(depth[x] == depth[y]) depth[y]++;
            par[x] = y;
        }
        return;
    }
};
int main(){
    int i,j;
    cin >> n >> k >> l;
    UnionFind uf1, uf2;
    for(i = 0; i < k; i++){
        int p,q;
        cin >> p >> q;
        uf1.unite(p,q);
    }
    for(i = 0; i < l; i++){
        int p,q;
        cin >> p >> q;
        uf2.unite(p,q);
    }
    map<pair<int,int>,int> mp;
    for(i = 1; i <= n; i++){
        mp[make_pair(uf1.find(i), uf2.find(i))]++;
    }
    for(i = 1; i <= n; i++){
        cout << mp[make_pair(uf1.find(i),uf2.find(i))];
        if(i==n) cout << endl;
        else cout << " ";
    }
    return 0;
}

Measured memory_bytes: 16768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=103,INF=1<<30;

struct edge{int to,cap,rev;};

vector<edge> G[MAX];
int level[MAX];
int iter[MAX];

void add_edge(int from,int to,int cap){
    G[from].push_back((edge){to,cap,int(G[to].size())});
    G[to].push_back((edge){from,0,int(G[from].size())-1});
}

void BFS(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s] =0;
    que.push(s);
    while(!que.empty()){
        int v=que.front();que.pop();
        for(int i=0;i<G[v].size();i++){
            edge &e =G[v][i];
            if(e.cap>0&&level[e.to]<0){
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}

int DFS(int v,int t,int f){
    if(v==t) return f;
    for(int &i=iter[v];i<G[v].size();i++){
        edge &e =G[v][i];
        if(e.cap>0&&level[v]<level[e.to]){
            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;
    for(;;){
        BFS(s);
        if(level[t]<0) return flow;
        memset(iter,0,sizeof(iter));
        int f;
        while((f=DFS(s,t,INF))>0){
            flow+=f;
        }
    }
}

int main(){

    int V,E;cin>>V>>E;
    for(int i=0;i<E;i++){
        int a,b,c;cin>>a>>b>>c;
        add_edge(a,b,c);
    }
    
    cout<<max_flow(0,V-1)<<endl;
}




Measured memory_bytes: 3180
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    int n;cin>>n;
    vector<string> s(3);
    for(int i=0;i<3;++i)cin>>s[i];
    int res = 0;
    for(int i=0;i<n;++i){
        if(s[0][i]==s[1][i] && s[0][i]==s[2][i]);
        else if(s[0][i]==s[1][i] ||s[2][i]==s[1][i] ||s[0][i]==s[2][i] )res++;
        else res+=2;
    }
    cout<<res<<endl;
    return 0;
}

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

using namespace std;
int main()
{
    char s[1];
    scanf("%s",&s);

    if( s[0]>= 'a' && s[0]<= 'z' )
    {
        printf("a");
    }

    else if( s[0]>= 'A' && s[0]<= 'Z' )
    {
        printf("A");
    }

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;
constexpr ll MOD = 1000000007;

ll pm3(int x) {
  if (x == 0) return 1;
  if ((x%2) == 1) return (3*pm3(x-1))%MOD;
  ll h=pm3(x/2);
  return (h*h)%MOD;
}

int main()
{
  string l;
  cin>>l;
  int n=l.size();
  ll sum = 0;
  ll mul = 1;
  REP(i,n) {
    if (l[i] == '1') {
      sum += pm3(n-i-1) * mul;
      sum %= MOD;
      mul *= 2;
      mul %= MOD;
    }
  }
  sum += mul;
  sum %= MOD;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string.h>
#include <math.h>
#include <vector>
using namespace std;


int main() {
    int N = 0;
    int Na = 0;
    cin >> N;
    Na = N % 10;
    if (Na == 2 || Na == 4 || Na == 5 || Na == 7 || Na == 9) {
        cout << "hon";

    }
    else if (Na == 0 || Na == 1 || Na == 6 || Na == 8) {
        cout << "pon";
    }
    else {
        cout << "bon";
    }
    return 0;
}

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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

_i64 calc(_i64 value1, char oprator, _i64 value2) {
    switch (oprator) {
        case '+': return value1 + value2;
        case '-': return value1 - value2;
        case '*': return value1 * value2;
        case '/': return value1 / value2;
    }
}

int main() {
    {
        _time time(disable);
        _i64 a, b; char op;
        while(cin >> a >> op >> b && op != '?') { cout << calc(a, op, b) << endl; }
    }
    return 0;
}


Measured memory_bytes: 3184
#include <iostream>
#include <vector>
//#include <fstream>	// require freopen

using namespace std;

struct D{
	int m;
	int a;
	int b;
};

int main()
{
//	cut here before submit 
//	freopen ("testcase.db", "r", stdin );
	int n;

	while (cin >> n && n ) {
		vector<D> d(n);
		int m, a, b;
		int i,j;

		for (i = 0; i < n; ++i ){
			cin >> m >> a >> b;
			d[i].m = m;
			d[i].a = a;
			d[i].b = b;
		} // end for

		bool break_bridge = false;
		
		for (i = 0; i < n; ++i ){
			int sum = d[i].m;
			for (j = 0; j < n; ++j ){
				if (i != j && d[i].a >= d[j].a && d[i].a < d[j].b ){
					sum += d[j].m;
				} // end if
			} // end for
			if (sum > 150 ){
				break_bridge = true;
				break;
			} // end if
		} // end for
		
		if (!break_bridge ) {
			cout << "OK" << endl;
		}else{
			cout << "NG" << endl;
		} // end if
	} // end while
		
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/
signed main(){
	int n,x,t;
	cin>>n>>x>>t;
	cout<<(n+x-1)/x*t<<endl;

	return 0;
}

Measured memory_bytes: 3644
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
ll a,b;
int main()
{
    scanf("%lld%lld",&a,&b);
    if(a==b)
    {
        puts("1");
        return 0;
    }
    int r=63-__builtin_clzll(a^b);
    ll T=(1LL<<r);
    a=a%T;b=T+b%T;
    int k;
    if(b==T) k=-1; else k=63-__builtin_clzll(b-T);
    ll ans=T-a;
    if(a<=(1LL<<(k+1))-1) ans+=T;
    else 
    {
        ans+=(1LL<<(k+1));
        ans+=T-a;
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 256
n=int(input())
d=[]
for _ in range(n):
  x,y=map(int,input().split())
  d.append([x,y])
  
for i in range(n-2):
  if d[i][0]==d[i][1] and d[i+1][0]==d[i+1][1] and d[i+2][0]==d[i+2][1]:
    print('Yes')
    exit()
print('No')

Measured memory_bytes: 62408
#include<iostream>
#include<cmath>

using namespace std;

int main(){
    int n, k;
    int ans = 0, r = 0;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        if(pow(2,i) > k){
            ans += k;
            r++;
        }
    }
    cout << ans + pow(2,n-r) << endl;
}

Measured memory_bytes: 4260
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

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

    ll i,j,n;
    ll m,k;
    cin>>n>>m>>k;
    vector<ll> a(n+1), b(m+1);
    a[0]= 0;
    b[0]= 0;
    ll t;
    for(i=1;i<=n;i++) {
        cin>>t;
        a[i] = a[i-1]+t;
    }
    for(i=1;i<=m;i++) {
        cin>>t;
        b[i] = b[i-1]+t;
    }
    ll mxb = m, ans = 0;
    for(i=0;i<=n && a[i]<=k;i++)
    {
        for(j=mxb;b[j]>k-a[i];j--)
        {
            mxb = j-1;
        }
        ans = max(ans,i+mxb);
    }
    cout<<ans;
}

Measured memory_bytes: 6356