akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int l, r; cin >> l >> r;

	if (r - l + 1 >= 2019) {
		cout << 0 << endl;
		return 0;
	}

	LL ans = INF2;
	for (LL i = l; i < r; i++) {
		for (LL j = l+1; j < r+1; j++) {
			LL val = i * j;
			val %= 2019;

			ans = min(ans, val);
		}
	}

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

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

int getDigit(int n, int digit)
{
    while (digit != 0) {n /= 10; digit--;}
    return n % 10;
}

int setDigit(int n, int digit, int value)
{
    int pow1 = 1;
    int d = 0;
    while (d < digit) {pow1 *= 10; d++;}
    n -= getDigit(n, digit) * pow1;
    n += value * pow1;
    return n;
}

int next1(int n)
{
    int idx = 0;
    while (getDigit(n, idx) == 7)
    {
        n = setDigit(n, idx, 3);
        idx++;
    }
    if (getDigit(n, idx) == 0) {n = setDigit(n, idx, 3);}
    else if (getDigit(n, idx) == 3) {n = setDigit(n, idx, 5);}
    else {n = setDigit(n, idx, 7);}
    return n;
}

bool valid(int n)
{
    int c3 = 0, c5 = 0, c7 = 0;
    int idx = 0;
    while (getDigit(n, idx) > 0)
    {
        int d = getDigit(n, idx);
        c3 += d == 3;
        c5 += d == 5;
        c7 += d == 7;
        idx++;
    }
    return c3 >= 1 && c5 >= 1 && c7 >= 1;
}

int next2(int n)
{
    n = next1(n);
    while (n >= 0 && !valid(n)) {n = next1(n);}
    return n;
}

int main()
{
    int n;
    cin >> n;
    int curr = 357;
    int result = 0;
    while (curr <= n && curr >= 0)
    {
        result++;
        curr = next2(curr);
    }
    cout << result << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])  
#define md 1000000007
#define MAXN 200005

int main()
{   
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    if (s.length() == t.length()-1) {
    	for (int i = 0 ; i < s.length() ; i++) {
    		if(s[i] != t[i]) {
    			cout << "No\n";
    			return 0;
    		}
    	}
    	cout << "Yes\n";
    }
    else {
    	cout << "No\n";
    }

    return 0;
}




Measured memory_bytes: 3568
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

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

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define lbd(a, x) lower_bound(all(a), x)
const int mod = 1e9 + 7;
int power_mod(int a, int b) {
	int res = 1;
	for(; b; b >>= 1, a = (ll) a * a % mod)
		if(b & 1) res = (ll) res * a % mod;
	return res;
}
const int N = 2e5 + 10;
int fac[N], ifac[N];
int C(int n, int m) {
	if(n < m || m < 0) return 0;
	return (ll) fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
  fac[0] = ifac[0] = 1;
  for(int i = 1; i < N; i++) fac[i] = (ll) fac[i - 1] * i % mod;
  ifac[N - 1] = power_mod(fac[N - 1], mod - 2);
  for(int i = N - 2; i; i--) ifac[i] = (ll) ifac[i + 1] * (i + 1) % mod;
  int n, m; cin >> n >> m;
  int a, b; cin >> a >> b;
  int res = C(n + m - 2, n - 1);
  for(int i = 0; i < a; i++) {
		res = (res - (ll) C(n - 1 - i + b - 1, b - 1) * C(m - b - 1 + i, i)) % mod;
  }
  if(res < 0) res += mod;
  cout << res << '\n';
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>

using namespace std;
const int maxn = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
typedef long long ll;

int n;
int a[maxn];
int main(){
	int m;
	cin >> n;
	int k = n - 1;
	while(k--){
		cin >> m;
		a[m]++;
	}
	for(int i = 1; i <= n; i++){
		cout << a[i] << endl;
	}
}

Measured memory_bytes: 4368
#include <iostream>
#include <vector>
#include <functional>

using namespace std;

int main()
{
    int N, Q;
    cin>>N>>Q;
    vector<vector<int>> E(N);
    for (int i=0; i<N-1; i++)
    {
        int a, b;
        cin>>a>>b;
        E[a-1].push_back(b-1);
        E[b-1].push_back(a-1);
    }
    vector<int> C(N);
    for (int i=0; i<Q; i++)
    {
        int p, x;
        cin>>p>>x;
        C[p-1] += x;
    }
    vector<int> ans(N);

    function<void(int, int, int)> f = [&](int c, int p, int x)
    {
        x += C[c];
        ans[c] = x;
        for (int e: E[c])
            if (e != p)
                f(e, c, x);
    };
    f(0, -1, 0);
    for (int i=0; i<N; i++)
        cout<<(i==0 ? "" : " ")<<ans[i];
    cout<<endl;
}


Measured memory_bytes: 30464
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    bool op=0;
    string l,r;
    int q;
    cin>>q;
    while (q--){
        int t;
        cin>>t;
        if (t==1)
            op=!op;
        else {
            int f;
            string c;
            cin>>f>>c;
            if (f==1){
                if(op)
                    r+=c;
                else
                    l+=c;
            }
            else{
                if (op)
                    l+=c;
                else
                    r+=c;
            }
        }
    }
    reverse(all(l));
    s=l+s+r;
    string cs=s;
    reverse(all(cs));
    if (op)
        cout<<cs;
    else 
        cout<<s;
}

Measured memory_bytes: 1544
from math import atan2, pi

N, *XY = map(int, open(0).read().split())
XY = list(zip(*[iter(XY)] * 2))

for i, (x, y) in enumerate(XY):
    D = sorted(atan2(X - x, Y - y) for j, (X, Y) in enumerate(XY) if j != i)
    D.append(D[0] + 2 * pi)

    print(min((b - a - pi for a, b in zip(D, D[1:]) if b - a > pi), default=0) / (2 * pi))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static boolean checkPrimeNum(int x) {
		int border = (int)Math.sqrt(x) + 1;

		for(int i = 2; i < border; i++) {
			if(x % i == 0) {
				return false;
			}
		}

		return true;
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int num = scan.nextInt();
		int x;
		int count = 0;

		for(int i = 0; i < num; i++) {
			x = scan.nextInt();
			if(checkPrimeNum(x)) {
				count++;
			}
		}

		System.out.println(count);

	}
}



Measured memory_bytes: 41544
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

bool mm(int x){
  if(1<=x && x<=12) return true;
  else return false;
}

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

  int l, r;
  l = s/100;
  r = s%100;

  if(mm(l) && mm(r)) cout << "AMBIGUOUS" << endl;
  if(mm(l) && !mm(r)) cout << "MMYY" << endl;
  if(!mm(l) && mm(r)) cout << "YYMM" << endl;
  if(!mm(l) && !mm(r)) cout << "NA" << endl;

  return 0;
}


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

using namespace std;

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

  string S; cin>>S;
  bool easy = true;
  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0) {
      easy &= S[i] != 'L';
    } else {
      easy &= S[i] != 'R';
    }
  }
  cout << (easy ? "Yes" : "No") << endl;

  return 0;
}


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

using namespace std;

int N,M,ST,EN;
char c;
struct edge {
	int v,f,next;
}e[40100];
int cnt = -1,head[210];

void adde (int u,int v,int f) {
	e[++cnt].v = v;
	e[cnt].f = f;
	e[cnt].next = head[u];
	head[u] = cnt;
	e[++cnt].v = u;
	e[cnt].f = 0;
	e[cnt].next = head[v];
	head[v] = cnt;
}
int dis[210],gap[210];

int dfs (int u,int minf) {
    if(u == EN)
        return minf;

    int chan = EN;
    int leff = minf;

    for(int i = head[u];i != -1;i = e[i].next) {
        int v = e[i].v;

        if(dis[v] == dis[u] - 1 && e[i].f) {
            int t = dfs(v,min(leff,e[i].f));
            e[i].f -= t;
            e[i ^ 1].f += t;
            leff -= t;

            if(dis[ST] >= EN + 1)
                return minf - leff;
			if(!leff)
				break;
        }
        if(e[i].f)
            chan = min(chan,dis[v]);
    }

    if(minf == leff) {
        --gap[dis[u]];
        if(gap[dis[u]] == 0)
            dis[ST] = EN + 1;
        dis[u] = chan + 1;
        ++gap[dis[u]];
    }
    return minf - leff;
}

void sap () {
	memset(gap,0,sizeof gap);
	memset(dis,0,sizeof dis);

    int ret = 0;
    gap[0] = EN + 1;
    while(dis[ST] < EN + 1)
        ret += dfs(ST,0x3f3f3f3f);
	if(ret > 10000)
		printf("-1\n");
	else printf("%d\n",ret);
}

int main () {
	memset(head,-1,sizeof head);
	scanf("%d%d",&N,&M);
	EN = N + M + 1;
	for(int i = 1;i <= N;++i) {
		for(int j = 1;j <= M;++j) {
			scanf(" %c",&c);
			if(c == 'o') {
				adde(i,j + N,1);
				adde(j + N,i,1);
			}
			if(c == 'S') {
				adde(0,i,0x3f3f3f3f);
				adde(0,j + N,0x3f3f3f3f);
			}
			if(c == 'T') {
				adde(i,N + M + 1,0x3f3f3f3f);
				adde(j + N,N + M + 1,0x3f3f3f3f);
			}
		}
	}
	sap();
}









Measured memory_bytes: 768
x=[0,0,0,0,0,0,1,2,3,-1,-2,-3]
y=[1,2,3,-1,-2,-3,0,0,0,0,0,0]

def dfs(ty,tx):
    if L[ty][tx]==1:
        L[ty][tx]=0
        for i,j in zip(x,y):
            dx,dy=tx+i,ty+j
            if 0<=dx<=7 and 0<=dy<=7:
                dfs(dy,dx)
    return

n=input()
for i in range(n):
    skip=raw_input()
    L=[map(int,raw_input()) for j in range(8)]
    ax,ay=input(),input()
    dfs(ay-1,ax-1)
    print "Data %d:"%(i+1)
    for j in range(8):
        print "".join(map(str,L[j]))

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

using namespace std;

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



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

    ll A, B;
    cin >> A >> B;
    cout << (A * B % 2 ? "Odd" : "Even");
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000009;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;

void solve() {
	ll a, b; cin >> a >> b;
	ll l, r; cin >> l >> r; l--; r--;
	ll ma = max(a, b);
	ll mi = min(a, b);
	ll c = (ma + mi) / (mi + 1);
	ll s = 0;
	ll ri = a + b+1;
	while (ri - s > 1) {
		ll mid = (s + ri)/2;
		ll ra = a - mid * c - 1;
		if (ra < 0) {
			ri = mid; continue;
		}
		ll rb = b - mid;
		if (rb < 1) {
			ri = mid; continue;
		}
		rb -= c;
		if (ra*c >= rb) {
			s = mid;
		}
		else {
			ri = mid;
		}
	}
	ll aa = a - s * c;
	ll bb = b - s;
	ll t = 0; ri = a + b + 1;
	while (ri - t > 1) {
		ll mid = (ri + t) / 2;
		if (aa <= mid || bb <= mid * c) {
			ri = mid; continue;
		}
		else {
			t = mid;
		}
	}
	ll x = aa - t;
	ll y = bb - c * t;
	if (y > c) {
		t++; x--; y -= c;
	}
	if (x > c) {
		s++; x -= c; y--;
	}
	//cout << s << " " << x << " " << y << " " << t << endl;
	string ans;
	Rep1(i, l, r) {
		if (i < s*(c + 1)) {
			if (i % (c + 1) == c) {
				ans.push_back('B');
			}
			else {
				ans.push_back('A');
			}
		}
		else {
			int r = i - s * (c + 1);
			if (r < x) {
				ans.push_back('A');
			}
			else if (r < x + y) {
				ans.push_back('B');
			}
			else {
				r -= x + y;
				if (r % (c + 1) == 0) {
					ans.push_back('A');
				}
				else {
					ans.push_back('B');
				}
			}
		}
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//init();
	int q; cin >> q;
	rep(i, q) {
		solve();
	}
	//cout << "finish" << endl;
	//stop
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) {return (x+y)%MOD;}
inline ll mul(ll x, ll y) {return (x*y)%MOD;}
inline ll sub(ll x, ll y) {
    ll res = x - y;
    if(res < 0) res += MOD;
    return res;
}

int main(){
    int N; cin >> N;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    sort(all(A),greater<ll>());
    multiset<ll> not_used;
    for(auto x:A) not_used.insert(x);
    int ans = 0;
    for(auto x:A) {
        if(not_used.find(x)==not_used.end()) continue;
        ll large = x;
        auto itr1 = not_used.find(large);
        not_used.erase(itr1);
        ll tmp = 1;
        while(tmp<=x) tmp*=2;
        ll small = tmp-x;
        if(not_used.find(small)!=not_used.end()){
            ans++;
            auto itr2 = not_used.find(small);
            not_used.erase(itr2);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        if(i%3==0 || i%5==0)continue;
        ans+=i;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> P(N), C(N);
    rep(i,N){
        cin >> P[i];
        P[i]--;
    }
    rep(i,N) cin >> C[i];
    
    vector<vector<ll> > point(N, vector<ll>(1));
    rep(i,N){
        point[i][0] = 0;
    }
    vector<ll> circle_count(N,0);
    for (ll i = 0; i < N; i++){
        ll start = i;
        ll count = 0;
        while(true){
            start = P[start];
            count++;
            point[i].push_back(point[i][point[i].size() - 1] + C[start]);
            if (start == i){
                circle_count[i] = count;
                break;
            }
        }
    }
    /*rep(i,N){
        cout << circle_count[i] << " ";
    }
    cout << endl;
    rep(i,N){
        rep(j,point[i].size()){
            cout << point[i][j] << " ";
        }
        cout << endl;
    }*/
    ll ans = -1000000000000000;
    rep(i,N){
        if (K <= circle_count[i]){
            for (ll j = 1; j <= K; j++){
                ans = max(ans, point[i][j]);
            }
        }
        else{
            if (point[i][circle_count[i]] < 0){
                for (ll j = 1; j <= circle_count[i]; j++){
                    ans = max(ans, point[i][j]);
                }
            }
            else{
                ll X = K / circle_count[i];
                ll Y = K % circle_count[i];
                if (Y == 0){
                    for (ll j = 1; j <= circle_count[i]; j++){
                        ans = max(ans, point[i][j] + (X - 1) * point[i][circle_count[i]]);
                    }
                }
                else{
                    for (ll j = 1; j <= Y; j++){
                        ans = max(ans, point[i][j] + X * point[i][circle_count[i]]);
                    }
                    for (ll j = Y + 1; j <= circle_count[i]; j++){
                        ans = max(ans, point[i][j] + (X - 1) * point[i][circle_count[i]]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 218944
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    LL l,r;
    cin>>l>>r;
    /*l=l%2019;
    r=r%2019;
    if(r<=l){r=r+2019;}*/
    //while(r>l+2019){r=r-2019;}
    LL min=2019;
    for(LL i=l;i<r;i++){
        for(LL j=i+1;j<=r;j++){
            if(((i*j)%2019)<min){min=((i*j)%2019);}
            if(min==0){break;}
        }
        if(min==0){break;}
    }
    cout<<min<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<int,int> P;
const ll MAX_N=131072;
const ll INF=1000000;
vector<int> G[1000010];
int main(){
  int N;
  cin>>N;
  vector<ll> a(N);
  rep(i,N) cin>>a[i];
  ll res=0;
  int right=0;
  ll num1=0;
  ll num2=0;
  for(int left=0;left<N;++left){
    while(right<N&&((num1^a[right])==(num2+a[right]))){
      num1^=a[right];
      num2+=a[right];
      ++right;
    }
    if (right==left) ++right;
    else{
      num1^=a[left];
      num2-=a[left];
    }
    res+=right-left;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 25344
// AGC033B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>

using namespace std;
using lolo=int;

bool hantei(const string& S, const string& T, lolo H, lolo W, lolo N, char L, char R, lolo sc, lolo sr)
{
	lolo right;

	if (L == 'L') {
		H = W;
		right = W - 1;
		sr = sc;
			
	}
	else {
		W = H;
		right = H - 1;
		sc = sr;
	}

	lolo left = 0;

	for (lolo i = N - 1; i >= 0; --i) {
		char s = S[i];
		char t = T[i];

		// キャンセルする青木くんの動き

		if (t == R) {
			if (left > 0 and left <= W - 1) {
				left -= 1;
			}
		}
		else if (t == L) {
			if (right < W - 1 and right >= 0) {
				right += 1;
			}
		}

		// OUT ゾーンを増やしていく
		if (s == L) {
			left += 1;
		}
		else if (s == R) {
			right -= 1;
		}
	}
	if (left <= sc and sc <= right) {
		return true;
	}
	else {
		return false;
	}
}

int main()
{
	using namespace std;
	using lolo=int;
	
	lolo H, W, N, sr, sc;
	string S, T;

	cin >> H >> W >> N;
	cin >> sr >> sc;
	sr--;
	sc--;

	cin >> S;
	cin >> T;
	
	bool yoko_safe = hantei(S, T, H, W, N, 'L', 'R', sc, sr);
	bool tate_safe = hantei(S, T, H, W, N, 'U', 'D', sc, sr);
	
	if (yoko_safe and tate_safe) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=2e5+100;
const ll inf=0x3f3f3f3f3f3f3f3f;
const ll mod=1e9+7;
ll t,n,k,a[maxn];
int main(){
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    ll res=0;
    for(int i=1;i<=n;i++) res+=i*(n+1-i);
    for(int i=1;i<n;i++){
        ll u,v;
        cin>>u>>v;
        if(u>v) swap(u,v);
        res-=u*(n+1-v);
    }cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2780>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
ll solve(){
    ll res = -1;
    ll N; cin >> N;
    vector<ll> a(N); for(auto& in:a) cin >> in;
    for(int i = 0; i < N;i++){
        for(int j = i+1; j < N;j++){
            ll A = a[i]*a[j];
            string sA = to_string(A);
            [&](){
                for(int k = 0; k < sA.length()-1;k++){
                    if(sA[k]-'0'+1==sA[k+1]-'0') continue;
                    return;
                }
                res = max(res,A);
            }();
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



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


int main() {

    vector<int> x(5);
    int index=0;
    for(int i=0;i<5;i++){
      cin>>x.at(i);

      if(x.at(i)==0)
        index=i;
    }

    cout<<index+1<<endl;

    return 0;
}

Measured memory_bytes: 3616
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define INF 1e9
#define MOD 1e9 + 7
int main() {
    int r, g, b;
    cin >> r >> g >> b;
    int ans = (100 * r + 10 * g + b) % 4;
    cout << (ans == 0 ? "YES" : "NO") << endl;
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int left, right;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A') {
            left = i;
            break;
        }
    }
    for (int j = s.size() - 1; j > left; j--) {
        if (s[j] == 'Z') {
            right = j;
            break;
        }
    }
    cout << right - left + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
bool is(int i){
	if(i%3==0||i%10==3)return true;
	while(i/=10)if(i%10==3)return true;
	return false;
}
int main(){
	int a=1,u;cin>>u;for(;a<=u;a++)if(is(a))cout<<" "<<a;cout<<endl;
}

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

string lcs(string s1,string s2){

    ll int n=s1.length();
    ll int m=s2.length();

    if(n==0 || m==0){
        return "";
        
    }

    vector<vector<ll int>> dp(n+1,vector<ll int> (m+1,0));


    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            
            if(s1[i-1]==s2[j-1]){
                dp[i][j]=1+dp[i-1][j-1];

            }else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }


    int s=n,e=m;

    string ans="";

    while(s>0 && e>0){

        if(s1[s-1]==s2[e-1]){
            ans+=s1[s-1];
            s--;
            e--;

        }else{
            if(dp[s][e-1]>dp[s-1][e]){
                e--;

            }else{

                s--;

            }
        }

    }

    reverse(ans.begin(),ans.end());


    return ans;


    

}

int main() {
    string s1,s2;
    cin>>s1>>s2;
    cout<<lcs(s1,s2);

}


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

using namespace std;
using ll = long long;
ll kaij(ll n) {
    if(n <= 1) {
        return 1;
    }
    return n*kaij(n - 1);
}
ll C(ll n, ll k) {
    //cout << "##" << endl;
    //cout << kaij(n) << endl;
    //cout << kaij(k) << endl;
    //cout << kaij(n - k) << endl;
    //return kaij(n)/(kaij(k)*kaij(n - k));
    int ans = 1;
    for(int i = 0; i < k; i++) {
        ans *= n - i;
        ans /= i + 1;
    }

    return ans;
}

//n桁のうちk個の数字が0でないとき
ll solve(ll n,ll k) {
    ////cout << "##" << endl;
    //cout << ':' << pow(9,k) << endl;
    //cout << '=' << C(n, k) << endl;
    return (ll)pow(9,k)*C(n, k);
}

int main() {
    string N;
    ll K;
    cin >> N >> K;
    ll n = N.size();
    string memoN = N;
    //cout << "##" << endl;
    //cout << kaij(5) << endl;
    //cout << N.at(0) - '0' << endl;
    //cout << solve(n - 1, K) << endl;
    ll ans;
    if(n < K) {
        cout << 0 << endl;
        return 0;
    }
    if(n > K) {
        ans = solve(n - 1, K);
    } else if(n == 1 && K == 1) {
        cout << N << endl;
        return 0;
    } else if(n == 2 && K == 2) {
        cout << stoi(N) - stoi(N)/10 - 9 << endl;
        return 0;
    } else if(n == 3 && K == 3) {
        int intN = stoi(N);
        cout << intN - intN/10 - 99 << endl;
        return 0;
    }
    //cout << ans << endl;
    //cout << "##" << endl;
    for(int i = 1; i < n; i++) {
        memoN.at(i) = '0';
    }
    //cout << "##" << endl;
    if(K == 3) {
        ans += (N.at(0) - '1')*solve(n - 1, K - 1);
        for(int i = 1; i < n; i++) {
            for(int j = i + 1; j < n; j++) {
                for(int k = 0; k < 9; k++) {
                    for(int l = 0; l < 9; l++) {
                        string checkN = memoN;
                        checkN.at(i) = '1' + k;
                        checkN.at(j) = '1' + l;
                        if(checkN <= N) {
                            ans++;
                        }
                    }
                }
            }
        }
    }
    if(K == 2) {
        ans += (N.at(0) - '1')*solve(n - 1, K - 1);
        for(int i = 1; i < n; i++) {
            for(int j = 0; j < 9; j++) {
                string checkN = memoN;
                checkN.at(i) = '1' + j;
                if(checkN <= N) {
                    ans++;
                }
            }
        }
    }
    if(K == 1) {
        ans += N.at(0) - '0';
    }

    cout << ans << endl;

    
    

    return 0;
}

Measured memory_bytes: 4032
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll countn = 0;
	ll countm = 0;
	ll memoa = 0;
	ll memob = 0;
	ll countx = 0;
	ll county = 0;
	countn = b - b / c;
	countm = b - b / d;
	memoa = b - b / lcm(c, d);
	countx = (a-1) - (a-1) / c;
	county = (a-1) - (a-1) / d;
	memob = (a-1) - (a-1) / lcm(c, d);
	cout << (countn + countm - memoa) - (countx + county - memob) << endl;
}

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

int main() {
    string S; cin >> S;
    vector<char> a(S.size());
    map<char, int> hey;
    for (char x = 'a'; x <= 'z'; x++) hey[x] = 0;
    for (int i = 0; i < S.size(); i++) {
        a.at(i) = S.at(i);
        hey.at(a.at(i))++;
    }
    for (char x = 'a'; x <= 'z'; x++) {
        if (hey.at(x) == 0) {
            cout << x << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#define MV 600
using namespace std;
typedef pair<int,int>P;
int W,H,N,Cs[2],Ce[2],X,Y,T,c1=0,c2=0,G[MV][MV]={0},V[MV][MV],v[MV][MV]={0},d[MV][MV],mx[4]={0,0,1,-1},my[4]={1,-1,0,0};//D,U,R,L
char S[1005],mp[255];
int main()
{
	mp['D']=0;mp['U']=1;mp['R']=2;mp['L']=3;
	scanf("%d%d%d",&W,&H,&N);
	scanf("%d%d%d%d",Cs,Cs+1,Ce,Ce+1);
	for(int i=0;i<N;i++)
	{
		scanf("%d%d",&X,&Y);
		scanf("%d%s",&T,S);
		for(int j=0;j<T;j++)
		{
			for(int k=0;S[k];k++)
			{
				int nx=X+mx[mp[S[k]]];
				int ny=Y+my[mp[S[k]]];
				if(nx<0||nx>=W||ny<0||ny>=H)continue;
				if(nx==X)V[nx][max(ny,Y)]++;
				else G[max(nx,X)][ny]++;
				X=nx;
				Y=ny;
			}
		}
	}
	memset(d,0x7f,sizeof(d));
	d[Cs[0]][Cs[1]]=0;
	priority_queue<pair<int,P> >Q;
	Q.push(make_pair(0,make_pair(Cs[0],Cs[1])));
	for(;Q.size();)
	{
		int row=Q.top().second.first;
		int col=Q.top().second.second;
		int nxc=-Q.top().first;
		Q.pop();
		if(v[row][col])continue;
		v[row][col]=1;
		for(int i=0;i<4;i++)
		{
			int nx=row+mx[i];
			int ny=col+my[i];
			int nc=0;
			if(nx==row)nc=G[nx][min(ny,col)];
			else nc=V[min(nx,row)][ny];
			if(nx<0||nx>W||ny<0||ny>H||v[nx][ny]||d[nx][ny]<=nxc+nc)continue;
			d[nx][ny]=nxc+nc;
			Q.push(make_pair(-d[nx][ny],make_pair(nx,ny)));
		}
	}
	printf("%d\n",d[Ce[0]][Ce[1]]);
	return 0;
}

Measured memory_bytes: 9416
// Problem : B - Checkpoints
// Contest : AtCoder - AtCoder Beginner Contest 057
// URL : https://atcoder.jp/contests/abc057/tasks/abc057_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

double pi=acos(-1.0);
const int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int n,m;cin>>n>>m;
vp v(n),v2(m);cin>>v>>v2;
for(int i=0;i<n;i++)
{
	int dis=abst(v[i].f-v2[0].f)+abst(v[i].se-v2[0].se);
	int ind=0;
	for(int j=1;j<m;j++)
	{
		int x=abst(v[i].f-v2[j].f)+abst(v[i].se-v2[j].se);
		if(x<dis)
		dis=x,ind=j;
	}
	cout<<ind+1<<"\n";
}
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc101/tasks/abc101_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)

int main(void) {
    int n, a, b = 0;
    cin >> n;
    a = n;
    while (a > 0) {
        b += (a % 10);
        a /= 10;
    }
    if (n % b == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public static partial class Program
{
    public static void Main()
    {
        var n = CRL().ToInt();

        var ans = new int[100001];
        var memo = new int[12];

        memo[0] = 1;
        for (int i = 1; i <= 6; i++)
        {
            memo[i] = Math.Pow(6, i).ToInt();
        }

        for (int i = 1; i <= 5; i++)
        {
            memo[i + 6] = Math.Pow(9, i).ToInt();
        }

        //dp[i] -> i円引き出すときの最小手数
        for (int i = 1; i <= n; i++)
        {
            ans[i] = int.MaxValue;
            for (int j = 0; j < 12; j++)
            {
                if (memo[j] > i)
                {
                    continue;
                }

                ans[i] = Math.Min(ans[i], ans[i - memo[j]] + 1);
            }
        }

        CWL(ans[n]);
    }
}

public static partial class Program
{
    //テンプレここから
    public static int ToInt(this double d) => (int) d;
    public static int ToInt(this string str) => int.Parse(str);
    public static long ToLong(this string str) => long.Parse(str);
    public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
    public static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
    public static int[] ArrayInts(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static string CRL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Sign(this long i) => Math.Sign(i);
    public static bool IsEven(this long i) => i % 2 == 0;
    public static bool IsEven(this int i) => i % 2 == 0;
    public static long[] dx = new long[] {0, -1, 0, 1};
    public static long[] dy = new long[] {-1, 0, 1, 0};
    public static long mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static long ToLong(this char c) => c.ToString().ToInt();
    public static long[] Sort(this long[] array) => array.OrderBy(x => x).ToArray();
    public static int[] Sort(this int[] array) => array.OrderBy(x => x).ToArray();
    public static long[] DSort(this long[] array) => array.OrderByDescending(x => x).ToArray();
    public static int[] DSort(this int[] array) => array.OrderByDescending(x => x).ToArray();
    public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);

    public static long LCM(long a, long b) => a * b / GCD(a, b);

    //テンプレここまで
}

Measured memory_bytes: 11232
#include<stdio.h>
#include<math.h>

int main()
{
    long long n,x,cnt=2;///n and n-1

    scanf("%lld",&n);
  
  	if(n==2)
    {
        printf("1");
        return 0;
    }

    int root=sqrt(n);

    for(int i=2;i<=root;i++)
    {
        if(n%i==0)
        {
            x=n;

            while(x%i==0)
                x/=i;

            if(x%i==1)
                cnt++;
        }
    }

    n--;
    root=sqrt(n);

    for(int i=2;i<=root;i++)
    {
        if(n%i==0)
        {
            if(n/i==i)
                cnt++;
            else
                cnt+=2;
        }
    }

    printf("%lld",cnt);

    return 0;
}


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

int main()
{
    int a,b,pluss,minuss,mul;
    cin>>a>>b;
    pluss=a+b;
    minuss=a-b;
    mul=a*b;
   int ans = max(pluss,minuss);
   cout<<max(ans,mul)<<endl;

}


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


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

	queue<ll> q;
	for (int i = 1; i <= 9; i++) {
		q.push(i);
	}

	ll ans;
	rep(ki, k) {
		ll a = q.front(); q.pop();
		ans = a;
		if (a % 10 == 0) {
			q.push(a * 10 + 0);
			q.push(a * 10 + 1);
		}
		else if (a % 10 == 9) {
			q.push(a * 10 + 8);
			q.push(a * 10 + 9);
		}
		else {
			q.push(a * 10 + a % 10 - 1);
			q.push(a * 10 + a % 10 );
			q.push(a * 10 + a % 10 + 1);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int32_t N, M;
	cin >> N >> M;

	vector<vector<int32_t>> g(N);
	for (int32_t i = 0; i < M; i++) {
		int32_t a, b;
		cin >> a >> b;
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}

	vector<int32_t> next_island(g[0].size());
	for (size_t i = 0; i < g[0].size(); i++) {
		next_island[i] = g[0][i];
	}
	for (size_t i = 0; i < next_island.size(); i++) {
		for (size_t j = 0; j < g[next_island[i]].size(); j++) {
			int32_t num = g[next_island[i]][j];
			if (num == 0)
				continue;
			if (num == N - 1) {
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
	}

	cout << "IMPOSSIBLE" << endl;

	return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int maxn = 60;
const ll oo = 1ll<<60;
ll memo[maxn][maxn][3],C[maxn];
string str[maxn];
int N;

//0 derecha
//1 izquierda
string get(string &tmp,int pos,int dir){
	string res = "";
	if(dir == 0){
		forr(i,(int)tmp.size()-1,pos)res += tmp[i];
	}else{
		forr(i,pos,0)res += tmp[i];
	}
	return res;
}
int sufijo(string &tmp,string &necesito){
	int ini = necesito.size()-1,fin = tmp.size()-1;
	int res = 0;
	int i = 0;
	while(i < (int)min(tmp.size(),necesito.size())){
		if(necesito[ini] != tmp[fin])break;
		ini--; fin--;
		res++;
	}
	return res;
}

int prefijo(string &tmp,string &necesito){
	int ini = 0,fin = 0;
	int res = 0;
	int i = 0;
	while(i < (int)min(tmp.size(),necesito.size())){
		if(necesito[ini] != tmp[fin])break;
		ini++; fin++;
		res++;
	}
	return res;
}

bool palindromo(string a){
	string aa = a;
	reverse(all(aa));
	return a == aa;
}

ll dp(int pos1,int pos2,int dir){
	if(pos2 >= (int)str[pos1].size() || pos2 < 0)return 0;
	ll &res = memo[pos1][pos2][dir];
	if(res != -1)return res;
	res = oo;
	string necesito = get(str[pos1],pos2,dir);
	if(palindromo(necesito)){
      res = 0;
      return res;
    }
	forn(i,0,N){
		if(dir == 0){
			int cnt = sufijo(str[i],necesito);
			if(!cnt)continue;
			if(cnt < (int)necesito.size() && cnt < (int)str[i].size())continue;
			if(cnt < (int)necesito.size()){
				res = min(res,C[i]+dp(pos1,pos2+cnt,dir));
			}else{
				res = min(res,C[i]+dp(i,(int)str[i].size()-1-cnt,!dir));
			}
		}else{
			int cnt = prefijo(str[i],necesito);
			if(!cnt)continue;
			if(cnt < (int)necesito.size() && cnt < (int)str[i].size())continue;
			if(cnt < (int)necesito.size()){
				res = min(res,C[i]+dp(pos1,pos2-cnt,dir));
			}else{
				res = min(res,C[i]+dp(i,cnt,!dir));
			}
		}
	}
	return res;
}
#define no cout << "-1\n";
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	forn(i,0,maxn)forn(j,0,maxn)forn(k,0,3)memo[i][j][k] = -1;
	cin >> N;
	forn(i,0,N)cin >> str[i] >> C[i];
	ll res = oo;
	forn(i,0,N)if(palindromo(str[i]))res = min(res,ll(C[i]));
	forn(i,0,N)res = min(res,C[i]+dp(i,0,0));
	if(res >= oo){
		no;
		return 0;
	}
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 3748
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

ll h[100001];
ll d[100001];
int  main() {
	ll n; cin >> n;
	repe(i, 1, n)cin >> h[i];

	rep_r(i, 1, n) {
		if (h[i] >= h[i + 1]) {
			d[i] = d[i + 1] + 1;
		}
		else {
			d[i] = 0;
		}
	}
	ll maxV = 0;
	rep(i, 1, n) {
		maxV = max(maxV, d[i]);
	}
	cout << maxV << endl;

	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
using namespace std;
int main( ){
  while(1){
    int n,a,sum=0,max=0,min=1001;
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>a;
      sum+=a;
      if(a>max)max=a;
      if(a<min)min=a;
    }
    cout<<(sum-max-min)/(n-2)<<endl;
  }
  return 0;
}

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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 100000;
const int MAX_K = 30;

string S, T;
set<int> st[MAX_K+1];
vector<int> s, t;
ll ans;
int N;

int main(){
	cin>>S>>T;
	N = S.size();
	for(int i=0; i<S.size(); i++){
		s.pb(S[i]-'a');
		st[S[i]-'a'].insert(i);
	}
	for(int i=0; i<T.size(); i++){
		t.pb(T[i]-'a');
		if(st[T[i]-'a'].empty()){
			printf("-1");
			return 0;
		}
	}
	int prv=-1;
	for(int i=0; i<T.size(); i++){
		int now = t[i];
		int nxt;
		if(st[now].upper_bound(prv)==st[now].end()){
			ans += (ll)(N-1-prv);
			nxt = (*st[now].begin());
			ans+= (ll)(nxt+1);
		}else{
			nxt = (*st[now].upper_bound(prv));
			ans += (ll)(nxt - prv);
		}
		prv = nxt;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 6264
<?php
  list($n,$m) = explode(" ", trim(fgets(STDIN)));

  if($n==1) {
    echo $m;
    exit;
  }

  $ans = 1;
  for($i=1;$i*$i<=$m;$i++){
    if($m % $i == 0){
      $x = intdiv($m, $i);
      if($n <= $x){
        $ans = max($ans,$i);
      }
      if($n <= $i){
        $ans = max($ans,$x);
      }
    }
  }
  echo $ans;

Measured memory_bytes: 16224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
const int infty = static_cast <int> (pow(256, sizeof(int)) / 2 - 1);

int getTheNumberOfCoin(int n, int m, vector<int> &vc)
{
	vector<int> vt;

	for (int j = 0; j <= n; ++j)
	{
		vt.push_back(infty);
	}
	vt[0] = 0;

	for (int i = 0; i < m; ++i)
	{
		for (int j = vc[i]; j <= n; ++j)
		{
			vt[j] = min(vt[j], vt[j - vc[i]] + 1);
		}
	}
	return vt[n];
}

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

	int n,m;
	cin >> n >> m;
	cin.ignore();

	int a;
	vector<int> vc;

	for (int i = 0; i < m; ++i)
	{
		cin >> a;
		vc.push_back(a);
	}

	cout << getTheNumberOfCoin(n, m, vc) << endl;

	return 0;
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  ll N;
  cin >> N;
  vector<ll> vec;
  vec.push_back(3);
  vec.push_back(5);
  vec.push_back(7);
  vector<ll> vec2(vec);
  REP(i,8){
    vector<ll> vec3;
    for(auto x:vec2){
      vec3.push_back(x*10+3);
      vec3.push_back(x*10+5);
      vec3.push_back(x*10+7);
      vec.push_back(x*10+3);
      vec.push_back(x*10+5);
      vec.push_back(x*10+7);
    }
    vec2=vec3;
  }
  sort(ALL(vec));
  int cnt=0;
  REP(i,vec.size()){
    set<int> st;
    ll y = vec.at(i);
    while(y>0){
      st.insert(y%10);
      y/=10;
    }
    if(N>=vec.at(i)&&st.size()==3){
      cnt++;
    }else if(N<vec.at(i)){
      break;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 1016
N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]
weights = list(map(lambda x: x[0], items))
values = list(map(lambda x: x[1], items))
sum_weights = sum(weights)
sum_values = sum(values)

dp = [([0] + [sum_weights*2 for _ in range(sum_values)]) for _ in range(N+1)]

for i in range(N):
    for v in range(1, sum_values+1):
        if v - values[i] >= 0:
            dp[i+1][v] = dp[i][v-values[i]] + weights[i]
        
        dp[i+1][v] = min(dp[i+1][v], dp[i][v])
        
for i in reversed(range(sum_values+1)):
    if dp[N][i] <= W:
        print(i)
        break


Measured memory_bytes: 181504