akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll a[n];
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    ll dp[n][n+1], sz[n][n+1];
    for(int i = 0; i < n; ++i) {
        dp[i][1] = 0;
        sz[i][1] = a[i];
    }
    for(int l = 2; l <= n; ++l) {
        for(int i = 0; i+l-1 < n; i++) {
            dp[i][l] = LLONG_MAX;
            for(int m = 1; m <= l-1; m++)
                if(dp[i][m] + dp[i+m][l-m] + sz[i][m] + sz[i+m][l-m]
                        < dp[i][l]) {
                dp[i][l] = dp[i][m] + dp[i+m][l-m] + sz[i][m] + sz[i+m][l-m];
                sz[i][l] = sz[i][m] + sz[i+m][l-m];
                }
        }
    }
    cout << dp[0][n];
    return 0;
}


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

ll solve() {
    string S;
    cin >> S;
    int ans = 0, n = 0;
    for ( char c : S ) {
        if ( c != 'R' ) n = 0;
        if ( c == 'R' ) {
            n++;
            ans = max(ans, n);
        }
    }
    return (ll)ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int num = -INF;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        num = max(x, num);
        ans += x;
    }
    cout << ans - num / 2 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int field[110][110];
	int H,W,N;
	cin>>W>>H>>N;
	fx(H+1){
		fy(W+1){
			field[x][y]=1;
		}
	}
	
	fz(N){
		int xz,yz,a;
		cin>>xz>>yz>>a;
		switch(a){
			case 1:
			for(int x=0;x<xz;x++){
				for(int y=0;y<H;y++){
					field[y][x]=0;
				}
			}
			break;
			case 2:
			for(int x=xz;x<W;x++){
				for(int y=0;y<H;y++){
					field[y][x]=0;
				}
			}
			break;
			case 3:
			for(int x=0;x<W;x++){
				for(int y=0;y<yz;y++){
					field[y][x]=0;
				}
			}
			break;
			case 4:
			for(int x=0;x<W;x++){
				for(int y=yz;y<H;y++){
					field[y][x]=0;
				}
			}
			break;
			
		}
	}
	int ans=0;
	fx(H){
		fy(W){
			if(field[x][y]==1){ans++;}
		}

	}
	ce(ans)
}

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

int main()
{
    int n;
    cin>>n;
    int A[n+1], B[n];
    for(int i=0; i<=n; i++)
        cin>>A[i];
    for(int j=0; j<n; j++)
        cin>>B[j];
    long long count=0;
    for(int i=0; i<n; i++)
    {
        if(A[i] >= B[i])
            count+=B[i];
        else
        {
            int rem = B[i]-A[i];
            count += A[i];
            if(A[i+1] >= rem)
            {
                count += rem;
                A[i+1] -= rem;
            }
            else
            {
                count += A[i+1];
                A[i+1] = 0;
            }
        }
    }
    cout<<count;
}


Measured memory_bytes: 1024
import java.util.Scanner;


public class Main
{

	public static void main(String[] args)
	{
		// TODO Auto-ge
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			long x=sc.nextLong(),y=sc.nextLong(),z=sc.nextLong();
			if(y>z||(x==1 && y!=z))System.out.println(0);
			else if(y==z)System.out.println(1);
			else System.out.println((x-2)*(z-y)+1);
		}
	}

}


Measured memory_bytes: 27048
#include<bits/stdc++.h>
#define F(a,b,c,d) for (register int a=b;a<=c;a+=d)
#define FD(a,b,c,d) for (register int a=b;a>=c;a-=d)
using namespace std;
int main(){
	int n,m,d,c;
	cin>>n>>m;
	if (n>8 || m>8) cout<<":("<<endl;
	else
	cout<<"Yay!"<<endl; 
	return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int rooms[4][3][10]; //○棟○階○部屋
	int n;
	int b[999], f[999], r[999], v[999]; //b棟f階r番目v人　(v<0の場合退去)

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				rooms[i][j][k] = 0;
			}
		}
	}

	cin >> n;

	for (int l = 0; l < n; l++) {
		cin >> b[l] >> f[l] >> r[l] >> v[l];
		rooms[b[l]-1][f[l]-1][r[l]-1] = rooms[b[l]-1][f[l]-1][r[l]-1] + v[l];
	}

	for (int p = 0; p < 3; p++) {
		for (int m = 0; m < 3; m++) {
			for (int o = 0; o < 10; o++) {
				cout << " " << rooms[p][m][o];
			}
			cout << endl;
		}
		cout << "####################" << endl;
	}

	for (int q = 0; q < 3; q++) {
		for (int r = 0; r < 10; r++) {
			cout << " " << rooms[3][q][r];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
/*
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
*/
#define nl "\n"
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define p_un(a) ((void)a)
#define p_st(a) string(a)
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define naj ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define NL cout << endl;
#define sqr(x) (sqrt(x) * 1LL)
#define pcnt(i) __builtin_popcount(i)
#define up_b upper_bound
#define low_b lower_bound
#define lcm(a,b) (a * b) / __gcd(a, b)
#define REVERSE(a, n) reverse(a + 1, a + n + 1);
#define SORT(a, n) sort(a + 1, a + n + 1);
#define rsz resize

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ul;
typedef vector <ll> vl;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <int> vi;
typedef vector <string> vs;
typedef pair <ll, ll> pll;
typedef map <ll, ll> mll;
typedef set <ll> sl;
typedef set <char> sc;
typedef map <string, ll> msl;
typedef map <string, bool> msb;
typedef map <char, ll> mcl;
typedef map <string, string> mss;
typedef vector <vl> vvl;

const ll mxn = 1e6 + 1;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ld eps = 1e-9;
const ld PI = acos(-1);
const ld E = 2.71828;

#define int int64_t
#define FLN "inverse"

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

inline void joji(bool ok = 0) {naj;if(ok){freopen(FLN".in","r",stdin);freopen(FLN".out","w",stdout);}}

map <int, int> cnt;
              
main () {

	joji();        	
	int n;
	cin >> n;
	vl a(n + 1);
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		cnt[a[i]] ++;
	}
	for(int i = 1; i <= n; i++) 
		if(cnt[a[i]] > 1) return cout << "NO", 0;
	cout << "YES";
	return 0;
}





        
                                                             


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

vector<bool> visited;
vector<vi> langs;
vector<vi> graph;
void dfs(int pos) {
	visited[pos] = true;

	for (int n : graph[pos]) if (!visited[n]) dfs(n);
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, M; cin >> N >> M;
	visited.resize(N);
	langs.resize(M);
	graph.resize(N);

	F0R(i, N) {
		int K; cin >> K;
		F0R(j, K) {
			int L; cin >> L; --L;
			langs[L].push_back(i);
		}
	}
	F0R(i, M) {
		FOR(j, 1, langs[i].size()) {
			graph[langs[i][0]].push_back(langs[i][j]);
			graph[langs[i][j]].push_back(langs[i][0]);
		}
	}
	int comp = 0;
	F0R(i, N) if (!visited[i]) ++comp, dfs(i);
	print((comp==1) ? "YES" : "NO");
}

Measured memory_bytes: 11744
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll A[100000];
int cnt[40];
int main() {
	int N;
	ll K;
	cin >> N >> K;
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum += A[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 40; j++) {
			if ((A[i] & (1LL << j))) cnt[j]++;
		}
	}
	ll ans = 0;
	for (int i = 39; i >= 0; i--) {
		if ((K&(1LL << i)) == 0) continue;
		ll t = sum;
		for (int j = i - 1; j >= 0; j--) {
			if ((N - cnt[j]) > cnt[j]) {
				t += (N - 2 * cnt[j])*(1LL << j);
			}
		}
		ans = max(ans, t);
		sum += (N - 2 * cnt[i])*(1LL << i);
	}
	ans = max(ans, sum);
	cout << ans << endl;
}

Measured memory_bytes: 1024
/*
***************************************************************************
 name  : ITP1_05_A.cpp
 title : Print a Rectangle
 make  : 2018/08/15 tanabe
***************************************************************************
*/

// Library
#include <iostream> // standard input output object

main(void){
  int h; // height
  int w; // width
  int l; // line
  int c; // column

   // initialized input "h w"
  // continue h != 0 or w != 0
  // input "h w" at loop update
  for(std::cin >> h >> w;h || w;std::cin >> h >> w){
    // initialized l = 0
    // continue l < h
    // increment l at loop update
    for(l = 0;l < h;l++){
      // initialized c = 0
      // continue c < w
      // increment c at loop update
      for(c = 0;c < w;c++){
        std::cout << "#"; // input "#"
      }
      std::cout << std::endl; // new line
    }
    std::cout << std::endl; // new line
  }

}



Measured memory_bytes: 3104
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define MOD 1000000007
#define SIZE 100005
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
typedef struct LIST{
	int to;
	struct LIST *next;
}Edge;
void add_edge(Edge **edge,int s,int t){
	Edge *tmp=(Edge*)malloc(sizeof(Edge));
	tmp->to=t;
	tmp->next=edge[s];
	edge[s]=tmp;
	return;
}
void delete_edge(Edge **edge,int v){
	int i;
	Edge *e,*tmp;
	FOR(i,0,v){
		e=edge[i];
		while(e!=NULL){
			tmp=e->next;
			free(e);
			e=tmp;
		}
	}
	return;
}
Edge *edge[100000];
int size[100000];
int a[100000];
int dfs(int v,int prev){
	int cnt=0,s,max=0,t;
	Edge *e;
	if(size[v]==1) return a[v];
	for(e=edge[v];e!=NULL;e=e->next){
		if(e->to==prev) continue;
		s=dfs(e->to,v);
		cnt+=s;
		max=MAX(max,s);
	}
	t=a[v]*2-cnt;
	if(a[v]>cnt||a[v]<max||2*a[v]<cnt){
		puts("NO");
		exit(0);
	}
	return t;
}
int main(void)
{
	int n,x,y,i;
	scanf("%d",&n);
	FOR(i,0,n) scanf("%d",&a[i]);
	if(n==2){
		printf("%s\n",a[0]==a[1]?"YES":"NO");
		return 0;
	}
	FOR(i,0,n-1){
		scanf("%d%d",&x,&y);
		add_edge(edge,--x,--y);
		add_edge(edge,y,x);
		size[x]++,size[y]++;
	}
	for(i=0;size[i]==1;i++);
	printf("%s\n",dfs(i,-1)==0?"YES":"NO");
	delete_edge(edge,n);
	return 0;
}


Measured memory_bytes: 13312
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    b = list(set(s))
    a = len(list(set(s)))
    if a == 2 and s.count(b[0]) == s.count(b[1]) == 2:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    p = LI()
    ans = 0
    for i in range(1,n-1):
        if (p[i - 1] < p[i] and p[i] < p[i + 1]) or (p[i + 1] < p[i] and p[i] < p[i - 1]):
            ans += 1
    print(ans)
    return

#C
def C():
    n = II()
    d = LI()
    d.sort()
    ans = 0
    for i in range(d[-1]):
        if n // 2 == bisect_left(d, i):
            ans += 1
    print(ans)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 4592
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;

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

  int n;
  cin >> n;
  vector<int> csum(n+1, 0);
  rep(i,n) {
    int w;
    cin >> w;
    csum[i+1] = csum[i] + w;
  }

  int res = inf;
  rep(i,n+1) {
    int sum1 = csum[i];
    int sum2 = csum[n] - csum[i];
    res = min(res, abs(sum1-sum2));
  }

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using ll = long long;
using namespace std;
#define modmod 1000000007

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<n;i++)

/*
int N;
ll W;
const int MAX_N = 100;
const ll MAX_W = 1000000000;
ll w[MAX_N],v[MAX_N];

///////////// 深さ優先探索 (TLEした) //////////////////
// i番目以降の品物から重さの輪がj以下になるように選んだ時の
// 取りうる価値の総和の最大値を返す関数
ll rec(ll i, ll j){
    ll res;
    if(i == N){
        // 品物がもう残っていないときは、価値の和の最大値は0で確定
        res = 0;
    }else if(j < w[i]){
        // 残りの容量が足りず品物iを入れられないので、入れないパターンだけ処理
        // i+1 以降の品物のみを使った時の最大値をそのままこの場合の最大値にする。
        res = rec(i+1,j);
    }else{
        // 品物iを入れるか入れないか選べるので、両方試して価値の和が大きいほうを選ぶ
        res=max(rec(i+1, j), rec(i+1, j-w[i])+v[i]);
    }
    return res;
}
*/
///////////// メモ化再帰 ///////////////////

// メモ化テーブル
// dp[i][j]はi番目以降の品物から重さの和がj以下になるように選んだ時の価値の和の最大値を表す。
// -1なら未決定
// で、やろうとしたけど、Wが大きすぎるのでメモリが足りない。size of array is too largeになってしまう。
// と思ったら、v自体はintでいけるのかなこれ。→ダメだった。

/*
ll dp[MAX_N + 1][MAX_W + 1];

ll rec_dp(int i, ll j){

}*/

/////////// 漸化式 /////////////

// DPテーブル
// dp[i][j]はi番目以降の品物から重さの和がj以下になるように選んだ時の価値の和の最大値を表す。


int main(){
    int N;
    ll W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    ll cnt[4] = {};
    vector<ll> vs[4];

    for(int i = 0; i < N; i++){
        cin >> w[i] >> v[i];
        cnt[w[i]-w[0]]++;
        vs[w[i]-w[0]].push_back(v[i]);
    }

    sort(begin(vs[0]), end(vs[0]), greater<ll>());
    sort(begin(vs[1]), end(vs[1]), greater<ll>());
    sort(begin(vs[2]), end(vs[2]), greater<ll>());
    sort(begin(vs[3]), end(vs[3]), greater<ll>());

    ll result = 0;

    for(int a = 0; a <= cnt[0]; a++){
        for(int b = 0; b <= cnt[1]; b++){
            for(int c = 0; c <= cnt[2]; c++){
                for(int d = 0; d <= cnt[3]; d++){
                    ll wsm = 0;
                    wsm += a*(w[0] + 0);
                    wsm += b*(w[0] + 1);
                    wsm += c*(w[0] + 2);
                    wsm += d*(w[0] + 3);
                    if(W<wsm){
                        continue;
                    }
                    ll vsm = 0;
                    for(int i = 0; i < a; i++){
                        vsm += vs[0][i];
                    }
                    for(int i = 0; i < b; i++){
                        vsm += vs[1][i];
                    }
                    for(int i = 0; i < c; i++){
                        vsm += vs[2][i];
                    }
                    for(int i = 0; i < d; i++){
                        vsm += vs[3][i];
                    }
                    result = max(result,vsm);
                }
            }
        }
    }
    cout << result << endl;

    return 0;
}


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

int main() {
	int X;
	cin >> X;
	vector<int> pow_number;
	for (int i = 2; i <= sqrt(X); i++) {
		int tmp = i, p = 1;
		while (tmp <= X) {
			tmp *= i;
			p++;
		}
		pow_number.push_back(pow(i, p - 1));
	}

	int max_num = 0;
	for (int i = 0; i < (int)pow_number.size(); i++) {
		if (max_num < pow_number.at(i)) {
			max_num = pow_number.at(i);
		}
	}
	if (X == 1) {
		max_num = 1;
	}

	cout << max_num << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ld> sd;
typedef set<ll> sl;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define Plabs     ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
    Plabs;
    int n, q;
    cin >> n;
    map<int, int> m;
    int a;
    long long sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        sum =sum+a;
        m[a]++;
    }

    cin >> q;
    long long b, c;
    for (int i = 0; i < q; i++)
    {
        cin >> b >> c;
        sum =sum-( m[b] * b);
        sum = sum+(m[b] * c);
        m[c]=m[c]+ m[b];
        m[b] = 0;
        cout << sum <<'\n';
    }

}











Measured memory_bytes: 7972
/*
???road[k][g[0]]+road[k][g[1]]??????(k:any????????§)????°????????????¨?????£??????
???road[s][k]?????§??????????????¨??????????°??????¨??????????????????
??????road[k][g[0]]+road[k][g[1]]?????§???????????????road[s][k]????°????????????°???????¨????????°?????????????
*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

const int INF = 1e8;

int n ,m, s, g[2];
int road[105][105];

int main() {
  while(1){
    cin>>n>>m>>s>>g[0]>>g[1];
    if(n==0) break;
    s--; g[0]--; g[1]--;
    REP(i,0,n)REP(j,0,n){
      if(i==j) road[i][j] = 0;
      else road[i][j] = INF;
    }
    REP(i,0,m){
      int b1,b2,c;
      cin>>b1>>b2>>c;
      b1--; b2--;
      road[b1][b2] = c;
    }
    REP(k,0,n){
      REP(from,0,n){
        REP(to,0,n){
          road[from][to] = min(road[from][to], road[from][k]+road[k][to]);
        }
      }
    }
    int ans = INF;
    REP(k,0,n){
      ans = min(ans, road[s][k] + road[k][g[0]] + road[k][g[1]]);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3112
import itertools
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        H, W = map(int, input().split())
        S = [input().rstrip() for _ in range(H)]

        for h in range(H):
            for w in range(W):
                if S[h][w] == '#':
                    continue

                cnt = 0
                for a in itertools.product((-1, 0, 1), repeat=2):
                    x, y = h + a[0], w + a[1]
                    if 0 <= x < H and 0 <= y < W and S[x][y] == '#':
                        cnt += 1
                S[h] = S[h][:w] + str(cnt) + S[h][w + 1:]
        print(*S, sep='\n')


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 40560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;



int main(){	
	long long K;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&K);
	if (K>(N-1)*(N-2)/2) {
		cout << "-1" << endl;
		return 0;
	}
	cout << N-1+((N-1)*(N-2)/2-K) << endl;
	priority_queue<P, vector<P>, greater<P> > que;
	for (ll i = 2; i <= N; i++) {
		for (ll j = i+1; j <= N; j++) {
			que.push(P(i, j));
		}
	}
	repn(i,N-1) {
		cout << "1 " << i+1 << endl;
	}
	repn(i,(N-1)*(N-2)/2-K) {
		P p = que.top(); que.pop();
		cout << p.first << " " << p.second << endl;
	}
	return 0;
}



Measured memory_bytes: 384
abcd = input()
num = [int(i) for i in abcd]
anslist = []
def solve(i,a,seven,ans):
    if i == 3:
        if seven == 7:
            return ans+'=7'
            
            
        else:
            return False

    if solve(i+1,a,seven+a[i+1],ans+'+'+str(a[i+1])):
        return solve(i+1,a,seven+a[i+1],ans+'+'+str(a[i+1]))
    
    if solve(i+1,a,seven-a[i+1],ans+'-'+str(a[i+1])):
        return solve(i+1,a,seven-a[i+1],ans+'-'+str(a[i+1]))

print(solve(0,num,num[0],str(num[0])))


Measured memory_bytes: 3064
n = int(input())
d = [list(map(int, input().split())) for i in range(n)]
cnt = 0

for i in range(0, n-2):
    cnt = 0
    if d[i][0] == d[i][1]:
        cnt += 1

        if d[i+1][0] == d[i+1][1]:
            cnt += 1

            if d[i + 2][0] == d[i + 2][1]:
                cnt += 1
                break

if cnt == 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9200
#include <iostream>

int abs(int a){
        if (a >= 0)
                return a;
        else
                return -a;
}

using namespace std;

int main(void){
        int a[1000] = {};

        int n;

        cin >> n;


        int id = 0;
        while (n != 0){
                int r = abs(n) % 2;
                a[id] = r;
                n = (n - r) / 2 * (-1);
                id++;
        }

        for (int i = max(id - 1, 0); i >= 0; i--)
                cout << a[i];
        cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}

ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}

int main() {
  cout << fixed << setprecision(30);
  ll h,n;
  cin>>h>>n;
  vec a(n);
  loop(i,n)cin>>a[i];
  ll s=sum(a);
  if(s>=h)putout("Yes");
  else putout("No");
}

Measured memory_bytes: 1024
n = int(input())
primINF = 2000000000
matrix = []
numV = n
for i in range(n):
    matrix.append(list(map(int, input().split())))

visited = [False] * numV
cost = [primINF] * numV # cost
parent = [-1] * numV # parent node

cost[0] = 0
parent[0] = -1

while True:
    # 訪問済み隣接の最小コストのノードを探索する
    mincost = primINF
    for i in range(n):
        if visited[i] is False and cost[i] < mincost:
            mincost = cost[i]
            u = i
    # 見つからなければ終了する
    if mincost == primINF:
        break
    # 訪問済みにする
    visited[u] = True
    for v in range(n):
        if visited[v] is False and matrix[u][v] != -1:
            if matrix[u][v] < cost[v]:
                cost[v] = matrix[u][v]
                parent[v] = u
res = 0
for i in range(n):
    if parent[i] != -1:
        res += matrix[i][parent[i]]

print(res)




Measured memory_bytes: 5892
/* Quick Note :
 * Jangan Mikir Lama - lama, sampahin dulu aja kalo OI
 * Always Try to reset
*/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll nax = 1e5 + 5;

struct cmp{
	bool operator()(ll x, ll y){
		return x > y;
	}
};

ll n;
ll mini[3*nax], a[3*nax];

int main(){ 
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    
    cin >> n;
    for(ll i = 1; i <= 3*n; i++){
		cin >> a[i];
	}
	priority_queue<ll> qmax;
	priority_queue<ll, vector<ll>, cmp> qmin;
	ll sum = 0;
	for(ll i = 3*n; i > n; i--){
		sum += a[i];
		qmax.push(a[i]);
		if(i <= 2 * n){
			sum -= qmax.top();
			qmax.pop();
		}
		mini[i] = sum;
		//debug(mini[i]);
	}
	sum = 0;
	ll ans = -inf;
	for(ll i = 1; i <= 2 * n; i++){
		sum += a[i];
		qmin.push(a[i]);
		if(i > n){
			sum -= qmin.top();
			qmin.pop();
		}
		if(i >= n){
			ans = max(ans, sum - mini[i+1]);
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 9516
/*
author : seryu
title : ABC177C_"Sum of product of pairs"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

void solve()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> cumsum(n+1, 0);
    rrep(i, n)
    {
        cumsum[i] = cumsum[i+1] + a[i];
        cumsum[i] %= MOD;
    }
    ll ans = 0;
    rep(i, n-1)
    {
        ans += a[i] * cumsum[i+1];
        ans %= MOD;
    }
    cout << ans << endl;
    return;	
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

public static class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var D = vals[0];
        var T = vals[1];
        var S = vals[2];

        if (D <= T * S)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 28276
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

#define yes printf("Yes\n")
#define Yes printf("YES\n")
#define no printf("No\n")
#define No printf("NO\n")

struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
//const long long mod = 998244353;
const long long mod = 1e9 + 7, inf = 3e18;
const string sp = " ";
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = max(a, b);
		return true;
	}
	return false;
}
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = min(a, b);
		return true;
	}
	return false;
}

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] *= fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int> factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

int n;
int s[222][222], d[222][222];
int ma = 0;
vector<int>v[222];
int co[222];
bool can;
bool dfs(int k, int c) {
	co[k] = c;
	for (int i : v[k]) {
		if (co[i] == c) return true;
		if (co[i] == 0 && dfs(i, -c)) return true;
	}
	return false;
}
signed main() {
	cin >> n;
	rep(i, n) {
		rep(j, n) {
			if (i != j) d[i][j] = inf;
		}
	}
	rep(i, n) {
		rep(j, n) {
			char a;
			cin >> a;
			if (a == '1') {
				d[i][j] = 1;
				v[i].push_back(j);
			}
		}
	}
	if (dfs(0, 1)) {
		cout << -1 << endl;
		return 0;
	}
	rep(k, n) {
		rep(i, n) {
			rep(j, n) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	rep(i, n) {
		rep(j, n) {
			ma = max(ma, d[i][j]);
		}
	}
	cout << ma + 1 << endl;
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
ans = A[0]

counter = 0
idx = 1
for _ in range(N-2):
  ans += A[idx]
  counter += 1
  if counter == 2:
    idx += 1
    counter = 0
print(ans)

Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
const int N = 3000300;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const int mod =    1e9+7;
int n,cnt0,cnt1,cnt2;
int arr[100005];
int main()
{ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n;

rep(i,1,n+1)
cin>>arr[i];
ll ans=1;
ll cnt=3;
rep(i,1,n+1)
{
	if(!(arr[i]))
	{
		ans*=cnt;
		cnt--;
		if(cnt==2)
		cnt0++;
		else if(cnt==1)
		cnt1++;
		else
		cnt2++;
		ans%=mod;

	}
	else
	{
		bool b=false;
	//	cout<<i<<" "<<endl;
		int x=0;
		if(cnt0==arr[i])
		{
		x++;cnt0++;
		b=true;}
		if(cnt1==arr[i])
		{
			x++;
			if(b==false)
			{
			cnt1++;
			b=true;}
}
		if(cnt2==arr[i])
		{
			x++;
			if(b==false)
			{
				cnt2++;
				b=true;
			}
}
		ans*=x;
		ans%=mod;
	}
}
cout<<ans%mod;



}

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

int main() {

	ll a, b; cin >> a >> b;
	if (b == 1) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	ll tap = a;
	while (tap < b) {
		ans++;
		tap += a - 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3524
#include <stdio.h>
int main(){
    int bingo[9];
    int sn;
    int sum=0;
    int N;

    for(int i=0;i<3;i++){
        scanf("%d %d %d",&bingo[i*3],&bingo[i*3+1],&bingo[i*3+2]);
    }
    scanf("%d",&N);

    
    for(int j=0;j<N;j++){
        scanf("%d",&sn);
        for(int i=0;i<9;i++){
            
            if(bingo[i]==sn){
                bingo[i]=0;
            }
        }
        
    }
    
    //yoko
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            sum+=bingo[i*3+j];
        }
        if(sum==0){
            printf("Yes\n");
            return 0;
        }
        sum=0;
    }

    //tate
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            sum+=bingo[j*3+i];
        }
        if(sum==0){
            printf("Yes\n");
            return 0;
        }
        sum=0;
    }

    //naname_hidariuekara
    for(int i=0;i<9;i+=4){
        sum+=bingo[i];
    }
    if(sum==0){
            printf("Yes\n");
            return 0;
    }
    sum=0;

    //
    for(int i=2;i<7;i+=2){
        sum+=bingo[i];
    }
    if(sum==0){
            printf("Yes\n");
            return 0;
    }
    sum=0;

    printf("No\n");
    return 0;
}

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

int main(){
    while(1){
        int a,b;
        char op;
        cin >> a >> op >> b;
        if(op=='?') break;

        int ans;
        if(op=='+') ans=a+b;
        if(op=='-') ans=a-b;
        if(op=='*') ans=a*b;
        if(op=='/') ans=a/b;
        cout << ans << endl;
    }
    return 0;
}



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

int main(){
    int n,ans;
    cin >> n;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin >> p.at(i);
    }
    for(int i=1;i<n-1;i++){
        if(p.at(i-1)<p.at(i)&&p.at(i)<p.at(i+1)){
            ans++;
        }
        if(p.at(i-1)>p.at(i)&&p.at(i)>p.at(i+1)){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static final int MAX_N = 200000;
    void run() {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        boolean[] c = new boolean[MAX_N+1];
        for (int i = 0; i < m; i++) {
            int a = scan.nextInt();
            int b = scan.nextInt();
            if (a == 1) {
                if (c[b]) {
                    System.out.println("POSSIBLE");
                    return;
                } else {
                    c[b] = true;
                }
            }
            if (b == n) {
                if (c[a]) {
                    System.out.println("POSSIBLE");
                    return;
                } else {
                    c[a] = true;
                }
            }
        }
        System.out.println("IMPOSSIBLE");
    }
    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 95192
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll  long long
ll a[300300], b[302000], vs[3000000];
vector<ll>v;

int main()
{
    IO;
    ll i, j=1, k = 0, mod = 1e9+7, m, mx, n, l = 1, p, t, h, kk=0, cnt=0;

    cin>>n>>m;
    for(i=1; i<=n; i++) j*=2;
    if(m==1&&n==1) return cout<<-1<<endl, 0;
    while(m){
        if(m%2&&l<1e6) vs[l]=1;
        m/=2; l*=2;
    }
    if(l/2>=j)cout<<-1<<endl;
    else {
        for(i=0; i<j; i++)
            if(!vs[i]) cout<<i<<' ';
        for(i=0; i<j; i++)
            if(vs[i]) cout<<i<<' ';
        for(i=j-1; i>=0; i--)
            if(!vs[i]) cout<<i<<' ';
        for(i=j; i>=0; i--)
            if(vs[i]) cout<<i<<' ';
    }
    return 0;
}


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

int calc(int state,vector<vector<int>>& v,vector<int>& cost,int x)
{
    int c=0;
    vector<int> skill(v[0].size(),0);
    for(int i=0;i<v.size();i++)
    {
        if(state & 1<<i)
        {
            for(int j=0;j<v[i].size();j++)
            {
                skill[j]+=v[i][j];
            }
            c+=cost[i];
        }
    }
    
    for(int i=0;i<skill.size();i++)
    {
        if(skill[i]<x)
            return INT_MAX;
    }
    
    return c;
    
}

int main() {
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> cost(n);
    vector<vector<int>> v(n,vector<int>(m));
    
    for(int i=0;i<n;i++)
    {
        cin>>cost[i];
        for(int j=0;j<m;j++)
        {
            cin>>v[i][j];
        }
    }
    
    int ans = INT_MAX;
    
    for(int i=0;i< (1<<n);i++)
    {
        ans = min(ans,calc(i,v,cost,x));
    }
    
    if(ans==INT_MAX)
        cout<<-1<<endl;
    else cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3660
// header {{{
// #define NDEBUG
#include <bits/stdc++.h>
using namespace std;

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)        (abs((a)-(b)) < EPS)
#define CILING(a, b)    (((a)+(b)-1LL)/(b))

template<class T>
using PIT = pair<int, T>;
template<class T>
using PTI = pair<T, int>;
using PII = pair<int, int>;
using PDI = pair<double, int>;
using LL  = long long;
using ULL = unsigned long long;
// }}}

int n;
int m;
LL memo[53][3][3];
vector<char> c[2];

LL dfs(int k, int s, int t) {
    if(memo[k][s][t] != -1) return memo[k][s][t];
    LL sum = 0;
    bool cflag = (c[0][k] == c[1][k]);
    if(cflag && s != t) return 0;
    if(!cflag && s == t) return 0;
    if(k == m-1) return 1;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(i != s && j != t){
                sum = (sum+dfs(k+1, i, j))%MOD;
            }
        }
    }
    /* if(sum > 0) cout << k << " " << s << " " << t << ":" << sum << endl; */
    return memo[k][s][t] = sum;
}

int main() {
    cin >> n;
    for(int i=0;i<2;i++){
        string s;cin >> s;
        char b = ' ';
        for(int j=0;j<n;j++){
            if(s[j] != b) c[i].push_back(s[j]);
            b = s[j];
        }
    }
    m = c[0].size();
    for(int i=0;i<m;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                memo[i][j][k] = -1;
            }
        }
    }
    LL ans = 0;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            ans = (ans+dfs(0, i, j))%MOD;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

immutable long MOD = 998244353;

void main() {
    auto N = readln.chomp.to!int;
    auto A = iota(N).map!(_ => readln.chomp.to!int).array;

    auto dp = new long[][][](2, 3, N*300+1);
    dp[0][0][0] = 1;

    int cur = 0;
    int tar = 1;

    foreach (i; 0..N) {
        foreach (j; 0..3) {
            dp[tar][j][] = 0;
        }
        foreach (j; 0..3) foreach (k; 0..N*300+1) if (dp[cur][j][k]) {
            (dp[tar][j][k+A[i]] += dp[cur][j][k]) %= MOD;
            if (j == 0) {
                (dp[tar][min(2, j+1)][k] += dp[cur][j][k] % MOD) %= MOD;
            } else if (j == 1) {
                (dp[tar][j][k] += dp[cur][j][k] % MOD) %= MOD;
                (dp[tar][min(2, j+1)][k] += dp[cur][j][k] % MOD) %= MOD;
            } else if (j == 2) {
                (dp[tar][min(2, j+1)][k] += dp[cur][j][k] * 2 % MOD) %= MOD;
            }
        }
        swap(cur, tar);
    }

    long ans = 0;
    int border = A.sum / 2 + A.sum % 2;

    foreach (k; border..N*300+1) {
        (ans += dp[cur][2][k] * 6) %= MOD;
    }

    ans = ((powmod(3, N, MOD) - ((powmod(2, N, MOD) - 2) * 3) - 3 - ans) % MOD + MOD) % MOD;
    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}


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

#define ll long long
#define endl "\n";
#define mod 1000000007
#define inf 1e18
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mp make_pair
#define all(a) a.begin(), a.end()
#define mk(arr,n,type) type *arr=new type[n];

void fastio() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int main() {
    fastio();
    int a,b;
    cin >> a >> b;

    if (b>=a) cout << "unsafe";
    else cout << "safe";

    return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAX 1400

int dp[MAX][MAX], G[MAX][MAX];

int getLargestSquare( int H, int W ) {
    int maxWidth = 0;
    for ( int i = 0; i < H; i++ ) {
        for ( int j = 0; j < W; j++ ) {
            dp[i][j] = (G[i][j] + 1) % 2;
            maxWidth |= dp[i][j];
        }
    }
    
    for ( int i = 1; i < H; i++ ) {
        for ( int j = 1; j < W; j++ ) {
            if ( G[i][j] ) {
                dp[i][j] = 0;
            }else {
                dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
                maxWidth = max(maxWidth, dp[i][j]);
            }
        }
    }
    
    return maxWidth * maxWidth;
}

int main(void) {
    int H, W;
    scanf("%d %d", &H, &W);
    
    for( int i = 0; i < H; i++ ) {
        for( int j = 0; j < W; j++ ) scanf("%d", &G[i][j]);
    }
    
    printf("%d\n", getLargestSquare(H, W));
    
    return 0;
}


Measured memory_bytes: 18072
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

// 250 -> 200
// 200 -> 200
// 199 -> 100
func round(n int) int {
	return n - n%100
}

func solve(a, b int) int {
	result := -1
	minv := 10
	maxv := 1009
	a *= 100
	b *= 100
	for i := minv; i <= maxv; i++ {
		tax1 := round(i * 8)
		tax2 := round(i * 10)
		if tax1 == a && tax2 == b {
			result = i
			break
		}
	}

	return result
}

func main() {
	a, _ := strconv.Atoi(input())
	b, _ := strconv.Atoi(input())
	fmt.Println(solve(a, b))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;



int main() {
   int n;
   cin >> n;
   bool flag = false;
   for (int i = 1;i <= 9;i++){
       if (n%i==0&&n/i<10) flag = true;

   }
   if(flag) cout << "Yes" << endl;
   else cout << "No" << endl;

}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  char s[3][101];
  scanf("%s%*c%s%*c%s",s[0],s[1],s[2]);
  int salen,sblen,sclen;
  salen=strlen(s[0]);
  sblen=strlen(s[1]);
  sclen=strlen(s[2]);
  int anum=0,bnum=0,cnum=0,num=0;
  while(1){
    if(num==0){
      if(anum==salen){
        puts("A");
        return 0;
      }
      if(s[num][anum]=='b')
        num=1;
      else if(s[num][anum]=='c')
        num=2;
      anum++;
    }
    else if(num==1){
      if(bnum==sblen){
        puts("B");
        return 0;
      }
      if(s[num][bnum]=='a')
        num=0;
      else if(s[num][bnum]=='c')
        num=2;
      bnum++;
    }
    else{
      if(cnum==sclen){
        puts("C");
        return 0;
      }
      if(s[num][cnum]=='a')
        num=0;
      else if(s[num][cnum]=='b')
        num=1;
      cnum++;
    }
  }
  return 0;
}

Measured memory_bytes: 1620