akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	int H, W;
	cin >> H >> W;
	char s[55][55];
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> s[i][j];
		}
	}
	int dx[4] = { 1,0,-1,0 };
	int dy[4] = { 0,1,0,-1 };
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (s[i][j] == '.')continue;
			bool can = false;
			for (int k = 0; k < 4; ++k) {
				int ny = i + dy[k];
				int nx = j + dx[k];
				if (nx >= 0 && nx < W&&ny >= 0 && ny < H) {
					if (s[ny][nx] == '#')can = true;
				}
			}
			if (!can) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void judge(double);

int main(void){
  double weight;

  while( scanf("%lf" ,&weight) != EOF ) judge(weight);
  
  return 0;
}

void judge(double weight){

  if( weight <= 48 ) printf("light fly\n");
  else if( weight <= 51 ) printf("fly\n");
  else if( weight <= 54 ) printf("bantam\n");
  else if( weight <= 57 ) printf("feather\n");
  else if( weight <= 60 ) printf("light\n");
  else if( weight <= 64 ) printf("light welter\n");
  else if( weight <= 69 ) printf("welter\n");
  else if( weight <= 75 ) printf("light middle\n");
  else if( weight <= 81 ) printf("middle\n");
  else if( weight <= 91 ) printf("light heavy\n");
  else printf("heavy\n");

}

Measured memory_bytes: 608
N,W=map(int,input().split())

def solve_knapsack(capacity):
    # basic checks
 
    
    # populate the capacity = 0 columns, with '0' capacity we have '0' profit
    dp = [0]*(W + 1)
    weights, profits = [0]*(N+1), [0]*(N+1)
    

    for i in range(0, N):
        weights,profits = map(int,input().split())
        for c in range(capacity, weights-1, -1):
            tmp = profits + dp[c - weights]
            if tmp > dp[c]: dp[c] = tmp
 
    # maximum profit will be at the bottom-right corner.
    return dp[capacity]
  
def main():
    
 
    res = solve_knapsack(W)
 
    print(res)
if __name__ == "__main__":
	main()

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

int abs(int x) {
	return x > 0 ? x : -x;
}

int main() {
	int N;
	cin >> N;
	int* a = new int[N];
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	sort(a, a + N);
	reverse(a, a + N);
	int alice = 0, bob = 0;
	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) {
			alice += a[i];
		} else {
			bob += a[i];
		}
	}
	cout << abs(alice - bob) << endl;
	delete[] a;
}

Measured memory_bytes: 256
n = int(input())
check = {}
for i in range(n):
    s = ["w"]*10
    c = 0
    for i in input():
        s[c] = i
        c += 1
    s.sort()
    s = "".join(s)
    if s in check:
        check[s] += 1
    else:
        check[s] = 1
ans = 0
for i in check.keys():
    ans += (check[i]-1)*check[i]/2
print(int(ans))

Measured memory_bytes: 63192
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        S: String,
    }
    let mut ans = true;
    let S = S.chars().rev().collect::<Vec<char>>();
    let words = vec!["dream","dreamer","erase","eraser"].iter().map(|x| x.chars().rev().collect::<Vec<char>>()).collect::<Vec<_>>();
    let mut i = 0;
    loop{
        let n = words.iter().filter_map(|w|{
            if S[i..].starts_with(w){
                Some(i + w.len())
            }else{
                None
            }
        }).next();
        if let Some(j) = n{
            i = j;
        }else{
            ans = false;
            break;
        }
        // 離脱判定
        if i >= S.len(){
            break;
        }
    }
    println!("{}", if ans{"YES"}else{"NO"});
}

Measured memory_bytes: 4352
def resolve():
    H, W, A, B = map(int, input().split())
    G = [[0] * W for _ in range(H)]

    for i in range(B):
        for j in range(A):
            G[i][j] = 1

    for i in range(B, H):
        for j in range(A, W):
            G[i][j] = 1

    for g in G:
        print(*g, sep="")


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 17756
#include<stdio.h>

#define TILES 6

typedef struct{
	int up;
	int front;
	int right;
	int left;
	int back;
	int bottom;
}dice;

int DiceRoll(dice* p, char c);

int main(void){
	dice a = {0, 0, 0, 0, 0, 0};
	int i=0, j=0;       // loop index
    int q=0;            // input; question times
    int u_content=0;    // input; up content
    int f_content=0;    // input; front content
    int u_label=-1;     
    int f_label=-1;
  
	// dice label setup 
    scanf("%d %d %d %d %d %d", &a.up, &a.front, &a.right, &a.left, &a.back, &a.bottom);

	scanf("%d", &q);

	for(i=0;i<q;i++){
		scanf("%d %d", &u_content, &f_content);
		if(a.up != u_content){
			j = 0;
			while(a.up != u_content && j < 3){
				DiceRoll(&a, 'E');
				j++;
			}
			if(a.up != u_content){
				while(a.up != u_content) DiceRoll(&a, 'N');
			}
		}
		if(a.front != f_content){
			while(a.front != f_content) DiceRoll(&a, 'R');
		}
		
		printf("%d\n", a.right);
	}

    return 0;
}

int DiceRoll(dice* p, char c){
	int tmp = -1;
	
	switch(c){
	case 'E':
		tmp = p->up;
		p->up = p->left;		// up <- left
		p->left = p->bottom;	// left <- bottom
		p->bottom = p->right;	// bottom <- right
		p->right = tmp;			// right <- up
		break;
	case 'N':
		tmp = p->up;
		p->up = p->front;		// up <- front
		p->front = p->bottom;	// front <- bottom
		p->bottom = p->back;	// bottom <- back
		p->back = tmp;			// back <- up
		break;
	case 'S':
		tmp = p->up;
		p->up = p->back;		// up <- back
		p->back = p->bottom;	// back <- bottom
		p->bottom = p->front;	// bottom <- front
		p->front = tmp;			// front <- up
		break;
	case 'W':
		tmp = p->up;
		p->up = p->right;		// up <- right
		p->right = p->bottom;	// right <- bottom
		p->bottom = p->left;	// bottom <- left
		p->left = tmp;			// left <- up
		break;
	case 'R':
		tmp = p->front;
		p->front = p->left;		// front <- left
		p->left = p->back;		// left <- back
		p->back = p->right;		// back <- right
		p->right = tmp;			// right <- front
		break;
	case 'L':
		tmp = p->front;
		p->front = p->right;	// front <- right
		p->right = p->back;		// right <- back
		p->back = p->left;		// back <- left
		p->left = tmp;			// left <- front
		break;
	default:
		break;
	}

	return 0;
}

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

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

	for(int i  = 0;i<=n;i++){
		if((ll)i*10000>y) break;
		for(int j = 0;j<=n-i;j++){
			if((ll)i*10000 + (ll)j*5000 + (ll)(n-i-j)*1000 > y) break;
			if((ll)i*10000 + (ll)j*5000 + (ll)(n-i-j)*1000 == y){
				cout<<i<<" "<<j<<" "<<(n-i-j);
				return 0;
			}
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1;
}

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

int main()
{
	int n;
	while(cin >> n){
		if(n==0)
			break;
		int sum[5000];
		int ma;
		for(int i=0;i<n;i++){
			cin >> sum[i];
			if(i!=0){
				sum[i] += sum[i-1];
				ma = max(ma,sum[i]);
			}
			else
				ma = sum[i];
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				ma = max(ma,sum[j]-sum[i]);
			}
		}
		cout << ma << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long 
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
const ll mod=998244353;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> data_struct;

int main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll p=ceil((double)a/(double)d);
	ll q=ceil((double)c/(double)b);
	if(p<q)
		cout<<"No";
	else
		cout<<"Yes";
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll r,d,x;cin >> r >> d >> x;
	rep(i,10){
		x = x * r - d;
		cout << x << endl;
	}
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m, n) {
    vector<int> mx(m);
    while (n--) {
      int d, v;
      cin >> d >> v;
      --d;
      mx[d] = max(mx[d], v);
    }
    int res = accumulate(begin(mx), end(mx), 0);
    cout << res << '\n';
  }
}



Measured memory_bytes: 3116
#!/usr/bin/env python3
m, k = map(int, input().split())

if 2**m - 1 < k:
    print(-1)
    exit()

if m == 1:
    if k == 0:
        print('0 0 1 1')
    else:
        print(-1)
    exit()

ans = [k]
left = []
for i in range(2**m):
    if i == k:
        continue
    left.append(i)
right = left[::-1]
ans = left + ans + right + ans
print(*ans)


Measured memory_bytes: 17296
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin >> n;
    int ans ;
    for(int i=0;i<n;i++){
        if(pow(2,i) > n){
            ans = pow(2,i-1);
            break;
        }
    }
    if(ans ==0){
        ans = 1;
    }
    cout << ans << endl;
    return 0;
}

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

int N;

class Q {
    public:
    int a,b;
    Q (int a,int b) :
        a(a),b(b) {
        };

    bool operator >(const Q &q) const {
        return a*q.b < b*q.a;
    }
    bool operator <(const Q &q) const {
        return a*q.b > b*q.a;
    }
    bool operator ==(const Q &q) const {
        return a*q.b == b*q.a;
    }


};

void solve() {
    vector<string> L(N);
    vector<pair<Q,string> > ans;
    rep(i,N) {
        string ss;
        int p,a,b,c,d,e,f,s,m;
        cin>>ss>>p>>a>>b>>c>>d>>e>>f>>s>>m;
        int mm = a+b+c;
        mm += (d+e)*m;
        int pp = f*s;
        pp = pp*m-p;
        Q q(pp,mm);
        ans.push_back(make_pair(q, ss));
    }
    sort(ans.begin(), ans.end());
    rep(i,ans.size()) {
        cout<<ans[i].second<<endl;
    }
}
int main() {
    while(cin>>N) {
        if(!N) return 0;
        solve();
        cout<<"#"<<endl;
    }

    return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,m;
    int c=0;
    cin>>s>>m;
    if(s[0]==m[0])
        c++;
    if(s[1]==m[1])
        c++;
    if(s[2]==m[2])
        c++;
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n, n_min, n_max, max, index;
    int data, tmp;

    while(1){
        scanf("%d %d %d", &n, &n_min, &n_max);

        if ( n == 0 && n_max == 0 && n_min == 0 ) break;

        for(int i = 0, data = 0, tmp = 0, max = -1; i < n; i++){
            tmp = data;
            scanf("%d", &data);
            if( n_min <= i && i <= n_max ){
                if( max <= tmp - data ){
                    index = i;
                    max = tmp - data;
                }
            }
        }
        printf("%d\n", index);
    }
    return 0;
}

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

int main() {
    unsigned long long int a[200000], sum = 0, n, mod = 1000000007, s = 0;
    cin>>n;
    for (int i = 0; i<n; i++)
    {    cin>>a[i];		s += a[i];	}
    for (int i = 0; i <n; i++)
    {
      s -= a[i];	
      sum = (sum + ((a[i]%mod) * (s%mod))) % mod;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 5180
N = 26
D = int(input())
C = [int(i) for i in input().split()]

S = []
for i in range(D):
  s = [int(i) for i in input().split()]
  S.append(s)
  
SUM = 0
L = [0] * 26
  
T = []
for i in range(D):
  t = int(input())
  T.append(t-1)

for i in range(D):
  d = i + 1
  for j in range(N):
    if j == T[i]:
      SUM += S[i][j]
      L[j] = d
    else:
   	  SUM -= C[j] * (d - L[j])
  else:
    print(SUM)


Measured memory_bytes: 9352
//lover~ crazy~
#include<bits/stdc++.h>
using namespace std;
int n;
int main() {
	cin>>n;
    for(int i=0;i<=30;i++)
        for(int j=0;j<=15;j++)
            if(i*4+j*7==n) {cout<<"Yes";return 0;}
    cout<<"No";
	return 0;
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;

using namespace std;

int main(void){
  ll h, n;
  cin >> h >> n;

  rep(i, n){
    int a;
    cin >> a;
    h -= a;
  }

  if(h <= 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string.h>
#include <stack>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
int main() {
    int x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2-x1;
    int dy = y2-y1;
    
    cout << x2-dy << " " << y2+dx << " " << x1-dy << " " << y1+dx << endl;
    return 0;
}


Measured memory_bytes: 3548
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N, M;
	cin >> N >> M;
	static int city[55][55];
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		city[a][b]++;
		city[b][a]++;
	}
	
	REP(i, N) {
		int cnt = 0;
		REP(j, N) {
			cnt += city[i][j] ;
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 256
no = "abcdefghijklmnopqrstuvwxyz"

def main():
    N = int(input())
    ans = ""
    while N > 0:
        N -= 1
        ans += no[N % 26]
        N //= 26
    return ans[::-1]

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 61668
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char ch[110000];
int n,K;
int main(){
	scanf("%s",ch+1);
	scanf("%d",&K);
	n=strlen(ch+1);
	for (int i=1;i<=n;i++){
		if (ch[i]=='a') continue;
		int k='z'-ch[i]+1;
		if (k<=K){
			K-=k; ch[i]='a';
		}
	}
	int k1=ch[n]-'a';
	k1=(k1+K)%26;
	ch[n]='a'+k1;
	for (int i=1;i<=n;i++) putchar(ch[i]); putchar('\n');
	return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換
int keta(ll n){int ans=0;while(n>0){n /= 10; ans++;}return ans;}
ll _pow(ll a,ll b){ll ans = 1;rep(i,b){ ans *= a;}return ans;}

int main() {
   int n;cin>>n;
   int s[n];
   int ans = 0;
   rep(i,n){
        cin>>s[i];
        ans += s[i];
        }
   sort(s,s+n);
   if(ans%10 != 0){
            cout<<ans<<endl;
            return 0;
        }
   rep(i,n){
       int D = ans;
        D-= s[i];
        if(D%10 != 0){
            cout<<D<<endl;
            return 0;
        }
        
   }
   cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>
void swing(int* a, int* b){
	int c;
	if(*a > *b){
		c = *b; *b = *a; *a = c;
	}
}
int main(void){
	int l, m, n;
	scanf("%d%d%d", &l, &m, &n);
	swing(&l, &m); swing(&l, &n); swing(&m, &n);
	printf("%d %d %d\n", l, m, n);
	return 0;
}


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

char ans[600][600];

void solve_odd(int h,int w,int d){
  for(int i = 0;i < h;++i){
    for(int j = 0;j < w;++j){
      if((i+j) % 2 == 0)
        ans[i][j] = 'R';
      else
        ans[i][j] = 'B';
    }
  }
}

void solve_even(int h,int w,int d){
  for(int i = 0;i < h;++i){
    for(int j = 0;j < w;++j){
      int a = ((i+j)/d)%2;
      int b = ((j-i+1000*d)/d)%2;
      if(a == 0 && b == 0){
        ans[i][j] = 'R';
      }else if(a == 0 && b == 1){
        ans[i][j] = 'G';
      }else if(a == 1 && b == 0){
        ans[i][j] = 'B';
      }else if(a == 1 && b == 1){
        ans[i][j] = 'Y';
      }
    }
  }
}

int main(void){
  int h,w,d;
  cin >> h >> w >> d;
  if(d % 2 == 1)solve_odd(h,w,d);
  else solve_even(h,w,d);
  for(int i = 0;i < h;++i){
    for(int j = 0;j < w;++j){
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 768
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

bool dp[80][80][12801]={};

bool CanAccess(int h,int w,int r,int c,int d){
  if(0<=r&&r<h&&0<=c&&c<w&&0<=d&&d<=12800){
    return true;
  }else{
    return false;
  }
}

int main(void){
  cout << std::fixed << std::setprecision(16);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int h,w;
  cin>>h>>w;
  const int offset=6400;

  int a[80][80]={};
  int b[80][80]={};

  for(int r=0;r<h;r++){
    for(int c=0;c<w;c++){
      cin>>a[r][c];
    }
  }

  for(int r=0;r<h;r++){
    for(int c=0;c<w;c++){
      cin>>b[r][c];
    }
  }
  dp[0][0][offset+a[0][0]-b[0][0]]=true;
  dp[0][0][offset+b[0][0]-a[0][0]]=true;

  for(int r=0;r<h;r++){
    for(int c=0;c<w;c++){
      int grid_diff_a=a[r][c]-b[r][c];
      int grid_diff_b=b[r][c]-a[r][c];
      for(int diff=-6400;diff<=6400;diff++){
        if(CanAccess(h,w,r-1,c,diff-grid_diff_a+offset)){
          if(dp[r-1][c][diff-grid_diff_a+offset]){
            dp[r][c][diff+offset]=true;
          }
        }
        if(CanAccess(h,w,r-1,c,diff-grid_diff_b+offset)){
          if(dp[r-1][c][diff-grid_diff_b+offset]){
            dp[r][c][diff+offset]=true;
          }
        }
        if(CanAccess(h,w,r,c-1,diff-grid_diff_a+offset)){
          if(dp[r][c-1][diff-grid_diff_a+offset]){
            dp[r][c][diff+offset]=true;
          }
        }
        if(CanAccess(h,w,r,c-1,diff-grid_diff_b+offset)){
          if(dp[r][c-1][diff-grid_diff_b+offset]){
            dp[r][c][diff+offset]=true;
          }
        }
      }
    }
  }

  int result=INT32_MAX;
  for(int diff=-6400;diff<=6400;diff++){
    if(dp[h-1][w-1][diff+offset]){
      result=std::min(result,abs(diff));
    }
  }
  cout<<result<<endl;


  return 0;
}


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

const int MOD=1000000007;
//~ const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll a[300000];

int main(){
	int n,K;cin>>n>>K;
	bool b=0;
	rep(i,n){
		scanf("%lld",&a[i]);
		if(a[i]>=0)b=true;
	}
	if(n==K||(!b&&(K%2==1))){
		sort(a,a+n,greater<>());
		ll ans=1;
		rep(i,K){
			(ans*=a[i])%=MOD;
		}
		cout<<(ans+MOD)%MOD<<endl;
		return 0;
	}
	priority_queue<ll>A,B;
	rep(i,n){
		if(a[i]>=0)A.push(a[i]);
		else B.push(-a[i]);
	}
	priority_queue<ll,vector<ll>,greater<ll>>usedA,usedB;
	rep(i,K){
		if(!A.empty()&&(B.empty()||A.top()>B.top()))usedA.push(A.top()),A.pop();
		else usedB.push(B.top()),B.pop();
	}
	if(!usedA.empty()&&usedA.top()==0){
		puts("0");return 0;
	}
	if(usedB.size()%2==1){
		if(!B.empty()&&!usedA.empty()&&(A.empty()||B.top()*usedB.top()>A.top()*usedA.top())){
			usedA.pop();usedB.push(B.top());
		}
		else{
			usedB.pop();usedA.push(A.top());
		}
	}
	ll ans=1;
	while(!usedA.empty())(ans*=usedA.top())%=MOD,usedA.pop();
	while(!usedB.empty())(ans*=usedB.top())%=MOD,usedB.pop();
	cout<<ans<<endl;
}

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

const long long maxn = 5e5 + 10;

long long n;
long long a[maxn];
long long ans;

void in();
void solve();
void out();

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n;
}

void solve(){
    long long t2 = 0, t5 = 0;
    if(n % 2 == 0){
        t2 += n/2;
        n /= 2;
        long long x = n;
        long long chiz = 1;
        while(x / (1 << chiz) > 0)
            t2 += x / (1 << chiz++);
        long long wow = 5;
        while(x / wow > 0){
            t5 += x / wow;
            wow *= 5;
        }
        ans = min(t2, t5);
    }
}

void out(){
    cout << ans;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "4 8 2" ].parse.expand.solve == 3 );
	assert( [ "0 5 1" ].parse.expand.solve == 6 );
	assert( [ "9 9 2" ].parse.expand.solve == 0 );
	assert( [ "1 1000000000000000000 3" ].parse.expand.solve == 333333333333333333 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abx = input.front.split.to!( long[] );
	return tuple( abx[ 0 ], abx[ 1 ], abx[ 2 ] );
}

auto solve( long a, long b, long x )
{
	auto bc = ( b == 0 ) ? 1L : b / x + ( a == 0 );
	auto ac = ( a == 0 ) ? 0L : ( a - 1 ) / x;
	return bc - ac;
}


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

int main()
{
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    ll ans=n;
    ll x=sqrt(n)+1;
    for(ll i=1;i<=x;i++){
        if(n%i==0){
            ans=min(ans,n/i+i-2);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


signed main() {
    string s;
    cin >> s;
    set<char> se;
    se.insert(s[0]);
    se.insert(s[1]);
    se.insert(s[2]);
    se.insert(s[3]);
    multiset<char> se2;
    se2.insert(s[0]);
    se2.insert(s[1]);
    se2.insert(s[2]);
    se2.insert(s[3]);
    if (se.size() != 2) {
        cout << "No" << endl;
        return 0;
    }
    if (se2.count(*se2.begin()) != 2) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

namespace BIT_ {
	using RET = int;
	constexpr int BUF = 1123456;
	int ptr = 0;
	RET t[BUF];
	inline RET* get(const int size) {
		ptr += size;
		return t + ptr - size;
	}
	inline void reset() {
		ptr = 0;
	}
}
//[1,n],0は扱えない!
struct BIT {
	using T = BIT_::RET;
	T* bit;
	int sz;
	BIT(int n) :bit(BIT_::get(n + 10)), sz(n) {
		fill(bit, bit + n + 10, 0);
	}
	T sum(int i) {
		T s = 0;
		while (i>0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	T sum(int lb, int ub) {
		return sum(ub) - sum(lb - 1);
	}
	void add(int i, T x) {
		while (i <= sz) {
			bit[i] += x; i += i & -i;
		}
	}
};

int N;
int dp[2123][2123];
int pos[2][2123];
constexpr int B = 1;
constexpr int W = 0;


int main() {
	cin >> N;
	for (int i : range(N*2)) {
		char c;
		int a;
		cin >> c >> a;
		pos[c == 'B'][a] = i + 1;
	}
	for (int i : range(N + 1)) {
		for (int j : range(N + 1)) {
			dp[i][j] = 1e8;
		}
	}
	dp[0][0] = 0;
	
	BIT bit(2 * N + 10);
	for (int i : range(2 * N))bit.add(i + 1, 1);
	for (int b : range(N + 1)) {
		for (int w : range(N + 1)) {
			if (b != N) {
				chmin(dp[b + 1][w], dp[b][w] + bit.sum(pos[B][b+1]) - 1);
			}
			if (w != N) {
				chmin(dp[b][w + 1], dp[b][w] + bit.sum(pos[W][w+1]) - 1);
			}
			if(w!=N)bit.add(pos[W][w + 1], -1);
		}
		for (int w : range(N)) {
			bit.add(pos[W][w + 1], +1);
		}
		if(b!=N)bit.add(pos[B][b + 1], -1);
	}
	cout << dp[N][N] << endl;
	return 0;
}


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

const int maxN = 1e6 + 10;

int n, m;
int sum[maxN + 1], mx[maxN + 1];
char s[maxN + 1];

inline int solve(int rule)
{
	int res = 0, mn = 0;
	for(int i = 1; i <= n; i++)
	{
		if(s[i] == '?' && mx[i] + res + 2 <= rule) res += 2;
		mn = min(mn, sum[i] + res);
	}
	return mn;
}

int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);

	for(int i = 1; i <= n; i++)
		if(s[i] == '1') sum[i] = sum[i - 1] + 1;
		else sum[i] = sum[i - 1] - 1;
	mx[n] = sum[n];
	for(int i = n - 1; i >= 1; i--) mx[i] = max(mx[i + 1], sum[i]);
	m = max(0, mx[1]);

	printf("%d\n", min(m - solve(m), m + 1 - solve(m + 1)));
	return 0;
}


Measured memory_bytes: 12492
def solve():
    n, m, x, y = map(int, input().split())
    xs = list(map(int, input().split()))
    xs.append(x)
    ys = list(map(int, input().split()))
    ys.append(y)
    return "War" if max(xs) >= min(ys) else "No War"


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,s,sum=0,mins=1e9;
	cin>>n;
	while(cin>>s){
		sum+=s;
		if(s%10!=0)
			mins=min(s,mins);
	}
	cout<<(sum%10==0?mins==1e9?0:sum-mins:sum)<<endl;
}


Measured memory_bytes: 256
/*

Author : AllKilled
Date   : 201911037

Contest: AtCoder Grand Contest 040.
Problem: Task A.
Result :

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

typedef long long LL;

const LL MAXN = 1e6+7;

///--------------------------------------------///

LL n, ans, dp[MAXN], pd[MAXN];
char s[MAXN];

LL get(LL x){
    return (x + 1) * x / 2;
}

int main()
{
    cin >> s+1;
    n = strlen(s+1) + 1;
    // <<<
    for (int i = 1; i < n; ++i){
        if(s[i] == '>') {
            if(s[i-1] == '<') ans += get(dp[i-1]);
            continue;
        }
        if (s[i] != s[i-1]) dp[i] = 1;
        else dp[i] = dp[i-1] + 1;
    }
    if(s[n-1] == '<') ans += get(dp[n-1]);
    //for(int i = 1; i < n; ++i) cout<<i<<" : "<<dp[i]<<endl; cout<<ans<<endl;
    // >>>
    for (int i = n - 1; i > 0; --i){
        if(s[i] == '<') {
            if(s[i+1] == '>') ans += get(pd[i+1]);
            continue;
        }
        if (s[i] != s[i+1]) pd[i] = 1;
        else pd[i] = pd[i+1] + 1;
    }
    if(s[1] == '>') ans += get(pd[1]);
    //for(int i = n - 1; i > 0; --i) cout<<i<<" : "<<pd[i]<<endl; cout<<ans<<endl;
    // <<<>>>
    for(int i = 1; i < n; ++i){
        if(s[i] == '<' && s[i+1] == '>') ans -= min(dp[i], pd[i+1]);
        //if(s[i] == '>' && s[i+1] == '<') ans -= 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int *a=new int[n];
  for(int i=0;i<n;i++)
  	a[i]=0;
  while(k--)
  {
    int d;
    cin>>d;
    while(d--)
    {
      int x;
      cin>>x;
      a[x-1]=1;
    }
  }
  int count=0;
  for(int i=0;i<n;i++)
  {
    if(a[i]==0)
      count++;
  }
  cout<<count<<"\n";
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


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

	int n;
	cin >>n;
	vector<VI> ab(n, VI(2)), cd(n, VI(2));
	rep(i, n) cin >>ab[i][0] >>ab[i][1];
	sort(all(ab), [](VI l, VI r){return l[1] != r[1]? l[1]>r[1]: l[0]>r[0];});
	rep(i, n) cin >>cd[i][0] >>cd[i][1];
	sort(all(cd));
	
	int ans =0;
	
	rep(i, n) rep(j, n){
		if(cd[i][0] > ab[j][0] && cd[i][1] > ab[j][1]){
			ans++; ab[j][0] = 9999999;
			break;
		}
	}
	cout << ans <<"\n";
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int L;
  cin >> L;
  long double ans = (double)L / 3;
  ans = pow(ans, 3);
  cout << setprecision(18) << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<bits/stdc++.h>
#define ll long long 

#define pb push_back
#define pii pair<int,int>
#define f(i,n) for(int i=0;i<n;i++)

using namespace std;


void solve(){
	
	char c;
	cin >> c;
	
	if(c-'a' >=0){
		cout<<'a'<<endl;
	}
	else{
		cout<<'A'<<endl;
	}
	
	
}

int main() {
	

	    solve();
	    
	return 0;
}


Measured memory_bytes: 3632
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-03-14 19:35:10
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    map<string, int> cnt;
    for (int i = 0; i < n; i++)
        cnt[s[i]]++;

    int m = 0;
    for (const auto& x : cnt) {
        int times = x.second;
        if (m < times) m = times;
    }

    for (auto iter = cnt.begin(); iter != cnt.end(); iter++) {
        if (iter->second == m) {
            cout << iter->first << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 26752
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <cstdio>
#include <bitset>
#include <map>
#include <string>


using namespace std;

int main()
{

    string text, pattern;

    while (cin >> text >> pattern)
    {       
        text += text;

        int j = 0, i = 0;
        while (text[j] != '\0' && pattern[i] != '\0')
        {
            if (text[j++] == pattern[i])
            {
                i++;            
            }
            else
            {
                j -= i;
                i = 0;                     
            }
   
        }

        if (pattern[i] == '\0')
            cout << "Yes";
        else
            cout << "No";
        
        cout << endl;        
    }


}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    ll L,R;
    cin >> L >> R;
    if(R-L>2019) cout << 0 << endl;
    else
    {
        ll ans = INF;
        for(ll i = L;i < R;i++) for(ll j = L;j <= R;j++) if(ans > (i*j)%2019 && i  < j) ans = (i*j)%2019;
        cout << ans << endl;
    }
}



Measured memory_bytes: 256
r,c = map(int, input().split())
data = [list(map(int, input().split())) for i in range(r)]
ans = 0
sita = []

for i in range(r):
  data[i].append(sum(data[i]))
  ans += sum(data[i])

for i in range(c):
  temp = 0
  for j in range(r):
    temp += data[j][i]
  sita.append(temp)
sita.append(ans//2)
data.append(sita)

for i in range(r+1):
  text = " ".join(map(str, data[i]))
  print(text)


Measured memory_bytes: 5704
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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 dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a;
map<ll,ll> m;


int main()
{
	string s, t;
	cin >> s >> t;
	bool flag = false;

	for (int i = s.length() - t.length(); i >= 0; i--) {
		flag = true;
		for (int j = 0; j <= t.length()-1; j++) {
			if (t[j] != s[i + j] && s[i + j] != '?') {
				flag = false;
			}
		}
		if(flag){
			for (int j = 0; j <= t.length()-1; j++) {
				s[i + j] = t[j];
			}
			break;
		}
	}

	if (!flag) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	else {
		for (int i = 0; i <= s.length() - 1; i++) {
			if (s[i] == '?') {
				s[i] = 'a';
			}
		}
	}
	cout << s << endl;


	return 0;
}





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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B,C;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C;
	if(A==B && A==C) {
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> connection(M, vector<int>(0));
    for (int i=0; i<M; i++)
    {
        int k;
        cin >> k;
        for (int j=0; j<k; j++)
        {
            int s;
            cin >> s;
            s--;
            connection[i].push_back(s);
        }
    }
    
    vector<int> amari(M);
    for (int i=0; i<M; i++) cin >> amari[i];

    int ans = 0;
    for (int i=0; i<(1<<N); i++)
    {
        bool all_bright=true;
        for (int j=0; j<M; j++)
        {
            int on_switch_num=0;
            for (int k=0; k<connection[j].size(); k++)
            {
                if (i&(1<<connection[j][k])) on_switch_num++;
            }
            if (on_switch_num%2 != amari[j]) all_bright=false;
            if (!all_bright) break;
        }
        if (all_bright) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve()
{
    ll a,b,c,d,A,B,C,D,e,f;
    cin>>a>>b>>c>>d;
    A=max(a,b)*max(c,d);
    B=min(a,b)*min(c,d);
    C=max(a,b)*min(c,d);
    D=min(a,b)*max(c,d);
    e=max(A,B);
    f=max(C,D);
    e=max(e,f);
    cout<<e<<endl;return;
}
int main()
{
    solve();
}

Measured memory_bytes: 3616
n,m = gets.split.map(&:to_i)

a = Array.new(n){[]}
m.times do
	u,v = gets.split.map(&:to_i)
	a[u-1] << v-1
end

s,t = gets.split.map{|x| x.to_i - 1}
b = Array.new(n){ Array.new(3, -3) }
b[s][0] = 0 
p = [[s,1]]

until (p.empty? || (b[t][0]!=-3))
	from,cnt = p.shift
	a[from].each do |to|
		if b[to][cnt] == -3
			b[to][cnt] = b[from][(cnt - 1)%3] + 1
			p << [to,(cnt+1) %3]
		end
	end
end

puts b[t][0]/3

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

const int MOD = 1e9 + 7;
int n, dp[3005][3005];
char a[3005];

void add(int &a, int b) {
	a += b;

	if(a >= MOD)
		a -= MOD;
}

int main() {
	scanf("%d%s", &n, a + 1);

	for(int i = 0; i <= n; i++)
		dp[n][i] = 1;

	for(int i = n - 1; i > 0; i--) {
		for(int j = 0; j <= n - i; j++) {
			if(j > 0)
				dp[i][j] = dp[i][j - 1];

			if(a[i] == '<') {
				if(j > 0)
					add(dp[i][j], dp[i + 1][j - 1]);
			}

			else {
				add(dp[i][j], dp[i + 1][n - i - 1]);

				if(j > 0)
					add(dp[i][j], MOD - dp[i + 1][j - 1]);
			}
		}
	}

	printf("%d\n", dp[1][n - 1]);
	return 0;
}

Measured memory_bytes: 35200
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
ll r[4005]={0};
ll g[4005]={0};
ll b[4005]={0};
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); }
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("text1.in","r",stdin);
	//freopen("text1.out","w",stdout);
	int n;
	cin>>n;
	string s;
	cin>>s;
	ll ans=0;
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='R'){
			r[i]=r[i+1]+1;
			g[i]=g[i+1];
			b[i]=b[i+1];
			ans=ans+g[i]*b[i];
		} 
		else if(s[i]=='G'){
			g[i]=g[i+1]+1;
			r[i]=r[i+1];
			b[i]=b[i+1];
			ans=ans+r[i]*b[i];
		} 
		else if(s[i]=='B'){
			g[i]=g[i+1];
			r[i]=r[i+1];
			b[i]=b[i+1]+1;
			ans=ans+r[i]*g[i];
		} 
	}
	for(int i=0;i<n;i++){
		int j=1;
		while(i+j*2<s.size()){
			if(s[i]!=s[i+j] && s[i+j]!=s[i+j+j] && s[i]!=s[i+j+j]){
				ans--;
			}
			j++;
		}	
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3712
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn
  let loop 0 (a,b,c) = return (a,b,c)
      loop i (a,b,c) = do
        [a',b',c'] <- map (read . BS.unpack) . BS.words <$> BS.getLine
        -- a,b,c <= 10^4
        loop (i - 1) (max b c + a', max a c + b', max a b + c')
  (a,b,c) <- loop n (0,0,0)
  {-
  happiness <- V.replicateM n $ do
    [a,b,c] <- map (read . BS.unpack) . BS.words <$> BS.getLine
    -- a,b,c <= 10^4
    return (a,b,c :: Int)
  let (a,b,c) = V.foldl1' (\(a,b,c) (a',b',c') -> (max b c + a', max a c + b', max a b + c')) happiness
  -}
  print (max a (max b c))


Measured memory_bytes: 67196
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int x,y;cin>>x>>y;
  vi v{0,1,3,1,2,1,2,1,1,2,1,2,1};
  
  string ans="No";
  if(v[x]==v[y])ans="Yes";
  cout(ans);
  
  return 0;
}

Measured memory_bytes: 125568
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(){
  int n,m;
  cin>>n>>m;
  vector<pair<int, int> > v[100001];
  for(int i = 0; i < m; i++){
    int a,b;
    cin>>a>>b;
    v[a].push_back(make_pair(b, i));
  }
  pair<int,int> ans[100001];
  for(int i = 1; i <= n; i++){
    sort(v[i].begin(),v[i].end());
    //県別にソート済みなので、その中の順番をjでまとめると良い
  for(int j = 0; j < v[i].size(); j++){
    ans[v[i][j].second] = make_pair(i,j+1);
  }
  }

  for(int i = 0; i < m; i++){
    cout<<setfill('0')<<right<<setw(6)<<ans[i].first<<setw(6)<<ans[i].second<<endl;
  }
  return 0;
}


Measured memory_bytes: 7808
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,K,C;
  cin>>N>>K>>C;
  string S;
  cin>>S;
  VI L(0),R(0);
  int tmp=-1;
  rep(i,N){
    if(tmp>i) continue;
    if(S[i]=='o'){
      L.pb(i);
      tmp=i+C+1;
    }
  }
  tmp=-1;
  rep(i,N){
    if(tmp>i) continue;
    if(S[N-1-i]=='o'){
      R.pb(N-1-i);
      tmp=i+C+1;
    }
  }
  VI LL(N+1),RR(N+1);
  rep(i,L.size()) LL[L[i]+1]++;
  rep(i,R.size()) RR[R[i]]++;
  rep(i,N) LL[i+1]+=LL[i];
  rep(i,N) RR[N-1-i]+=RR[N-i];
  rep(i,N) if(LL[i]+RR[i+1]<K) cout<<i+1<<endl;
}

Measured memory_bytes: 4984