akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=2020;
int nx[N],pv[N];
int solve(string s,string t){
    int n=sz(s);
    int f=-1;
    forn(i,n)if(t[i]=='1')f=i;
    forn(i,n){
        if(t[i]=='1')f=i;
        pv[i]=f;
    }
    f=-1;
    for(int i=n-1;i>=0;--i)if(t[i]=='1')f=i;
    for(int i=n-1;i>=0;--i){
        if(t[i]=='1')f=i;
        nx[i]=f;
    }
    int res=N+N;
    forn(shift,n){
        string a=s.substr(shift)+s.substr(0,shift);
        int pot=shift;
        vector<pii> v;
        forn(i,n){
            if(a[i]==t[i])continue;
            pot++;
            if(a[i]=='1'){
                int pos=nx[i],from=(i+shift)%n,l=0,r=0;
                if(i<=pos&&pos<=from){
                    //ok
                }else if(i<=from&&from<=pos){
                    l=(i-pv[i]+n)%n;
                    r=(pos-from+n)%n;
                }else if(pos<=i&&i<=from){
                    l=(i-pv[i]+n)%n;
                    r=(pos-from+n)%n;
                }else if(pos<=from&&from<=i){
                    //ok
                }else if(from<=i&&i<=pos){
                    //ok
                }else if(from<=pos&&pos<=i){
                    l=(i-pv[i]+n)%n;
                    r=(pos-from+n)%n;                 
                }else assert(0);
                if(l&&r)v.pb(l,r);
            }
        }
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        int lr=(N+N);
        int r=0;
        for(pii p:v){
            int l=p.f;
            upn(lr,l+r);
            upx(r,p.s);
        }
        upn(lr,r);
        pot+=lr*2;
        upn(res,pot);
    }
    return res;
}
int32_t main(){
    string s,t;
    cin>>s>>t;
    if(count(t.begin(), t.end(),'1')==0){
        if(s==t)cout<<"0\n";
        else cout<<"-1\n";
        return 0;
    }
    int ans=solve(s,t);
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    upn(ans,solve(s,t));
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define rs (x<<1|1)
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
const int N=200005;
int a[N];
int main(){
	int n,k;read(n);read(k);
	rep(i,1,n)read(a[i]);
	ll ans0=1,ans1=0;
	rep(i,1,n){
		if(a[i]&1){
			ans0=ans1=ans0+ans1;
		}else{
			ans0*=2ll;
			ans1*=2ll;
		}
	}
	if(!k)printf("%lld\n",ans0);
	else printf("%lld\n",ans1);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<pair<long,long> >p(n);
    for(int i=0;i<n;i++){
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(),p.end());
    cout << p[n-1].first + p[n-1].second << endl;
    
}


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

using namespace std;


int main (){

	string s,t;
  	cin>>s>>t;
  	int cnt=0;
  	
  	for(int i=0;i<3 ;i++){
    if(s.at(i)==t.at(i)) cnt++;
    
    }
  cout<<cnt<<endl;
  
  
  return 0;
}

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

#define For(i, j, k) for (int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (int i = j; i >= k; -- i)
#define Travel(i, u) for (int i = beg[u], v = to[i]; i; v = to[i = nex[i]])

using namespace std;

inline int read() {
	int x = 0, p = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') p = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x * p;
}

inline void File() {
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
}

const int N = 1e5 + 20, M = N << 1;
int n, m, t[N], a[N];

int main() {

	n = read(), m = read();

	For(i, 1, n) t[i] = 1; a[1] = 1;

	for (int x, y; m --; ) {
		x = read(), y = read();
	
		if (!t[x]) continue;	
		-- t[x], ++ t[y];
		if (a[x]) a[y] = 1;
		if (!t[x]) a[x] = 0;
	}
	
	int ans = 0;
	For(i, 1, n) ans += a[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

import sys
from itertools import permutations

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = MAP()
edges = set()
for i in range(M):
    a, b = MAP()
    a -= 1; b -= 1
    edges.add((a, b))
    edges.add((b, a))

cnt = 0
for perm in permutations(range(N)):
    if perm[0] != 0:
        continue
    for i in range(N-1):
        a = perm[i]
        b = perm[i+1]
        if (a, b) not in edges:
            break
    else:
        cnt += 1
print(cnt)


Measured memory_bytes: 3188
A, B, C, D, E, F = map(int, input().split())

CONCENT_LIMIT = E/(100+E)
max_concent = 0
water_at_max = 0
sugar_at_max = 0
for num_b in range(F//(100*B)+1):
    #print("B: ", num_b)
    rest_cap = F - num_b*B*100
    if rest_cap < 0:
        break
        
    for num_a in range(rest_cap//(100*A)+1):
        #print("  A: ", num_a)
        rest_cap_ = rest_cap - num_a*A*100
        water = num_b*B*100+num_a*A*100
        if rest_cap_ <= 0:
            break
        if water == 0:
            continue
            
        for num_d in range(rest_cap_//D+1):
            #print("    D: ", num_d)
            rest_cap__ = rest_cap_ - num_d*D
            if rest_cap__ < 0:
                break
                
            for num_c in range(rest_cap__//C+1):
                #print("      C: ", num_c)
                sugar = num_d*D+num_c*C
                if water+sugar > F:
                    break
                concent = sugar / (water+sugar)

                if (concent <= CONCENT_LIMIT) & (concent >= max_concent):
                    max_concent = concent
                    sugar_at_max = sugar
                    water_at_max = water
                
print(water_at_max+sugar_at_max, end=" ")
print(sugar_at_max)

Measured memory_bytes: 3064
// Author : Mohamed Sameh
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<stack>
#include<deque>
#include <cstring>
#include <iomanip>    
using namespace std ;
typedef long long ll ;

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define PI  3.141592 
#define SZ(a) (int)a.size()
void READ (string INPUT = "NO" , string OUTPUT = "NO" )
{
    if (INPUT != "NO")
    freopen(INPUT.c_str() , "r" , stdin );
    if (OUTPUT!="NO")
    freopen ( OUTPUT.c_str() , "w" , stdout);
} 
int n , w  ; 
ll dp[100001][101]; 
int h[100001][3]; 
ll solve (int i, ll curw )
{
    if (i == n)
        return 0; 
    if (dp[curw][i] != -1 )return dp[curw][i]; 
    ll &ret = dp[curw][i]; 
    ret = solve(i+1 ,curw ); 
    if (curw + h[i][0] <= w )
        ret = max (ret , h[i][1] + solve(i+1,curw+h[i][0])); 
    return ret ; 
}
int main ()
{
    memset (dp,-1,sizeof dp );
    scanf ("%d%d" , &n , &w); 
    for (int i =0 ; i < n ;i++)
        scanf ("%d%d" , &h[i][0] , &h[i][1] ); 
    printf ("%lld\n" , solve(0,0)); 
    return 0 ; 
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    ll ans;
    if(n <= b-1) ans = a * n / b;
    else ans = a * (b-1) / b;
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;

const int MAX_N = 1e5;
int n, h;
int a[MAX_N], b[MAX_N];

int main() {
    scanf("%d %d", &n, &h);
    for (int i = 0; i < n; i++) scanf("%d %d", &a[i], &b[i]);
    sort(a, a + n);
    sort(b, b + n);
    int ind = lower_bound(b, b + n, a[n - 1]) - b;
    
    int cnt = 0;
    while (ind + cnt < n) {
        h -= b[n - ++cnt];
        if (h <= 0) break;
    }

    if (h > 0) cnt += ceil(static_cast<double>(h) / a[n - 1]);

    printf("%d\n", cnt);
    return 0;
}


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

int main()
{
    int N,a[110];
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    sort(a, a + N,greater<int>());
    int s = 0;
    for (int i = 0; i < N; i++)
    {
        s += a[i] * (i & 1 ? -1 : 1);
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   	ll n,i,maxf=0;
   	cin >> n;
   	vector<string> v(n);
   	map<string,ll> m;
   	for(i=0;i<n;i++) {
   		cin >> v[i];
   		m[v[i]]++;
   		if(m[v[i]]>maxf) maxf=m[v[i]];
   	}
   	sort(v.begin(),v.end());
   	for(i=0;i<n;i++) {
   		if(m[v[i]]==maxf) {
   		 cout << v[i] << "\n";
   		 m[v[i]]=0;
   		}
   	}
    return 0;
}



Measured memory_bytes: 25472
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) L[i] = A[left + i];
    for (int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++){
        cnt++;
        if (L[i] <= R[j]){
            A[k] = L[i++];
        }
        else{
        A[k] = R[j++];
        }
    }
}

void mergeSort(int A[], int n, int left, int right){
    if (left+1 < right){
        int mid = (left + right)/2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int main(){
    int A[MAX], n, i;
    cnt = 0;

    cin >> n;
    for (i = 0; i < n; i++) cin >> A[i];

    mergeSort(A, n, 0, n);

    for (i = 0; i < n; i++){
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 6976
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;cin>>S;
  int ans = 0;
  repeat(i,6)ans += S[i]=='1';
  cout << ans << endl;
  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    string sa;
    sa += s[0];
    sa += s[1];
    string sb;
    sb += s[2];
    sb += s[3];
    if ("01" <= sa && sa <= "12" && "01" <= sb && sb <= "12")
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if ("01" <= sa && sa <= "12")
    {
        cout << "MMYY" << endl;
    }
    else if ("01" <= sb && sb <= "12")
    {
        cout << "YYMM" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
import math
from collections import Counter

def prime_factors(n):
  i = 2
  factors = []
  while i * i <= n:
    if n % i==0:
      n //= i
      factors.append(i)
    else:
      i += 1
  if n > 1:
    factors.append(n)
  return factors

mod=10**9+7
n=int(input())
num=math.factorial(n)
factors=prime_factors(num)
indices=Counter(factors)

ans=1

for i in indices.values():
  ans*=i+1
print(ans%mod)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e5;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX],n;
string s;
vector<string>v;
void gen(string x)
{
    sort(x.begin(),x.end());
    do
    {
        v.push_back(x);
    }
    while(next_permutation(x.begin(),x.end()));
}
int val(char x)
{
    if(x=='S')
        return 1;
    return 2;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>n>>s;
    gen("SSW");
    gen("SWW");
    v.push_back("SSS");
    v.push_back("WWW");
    for(int j=0; j<v.size(); j++)
    {
        arr[0]=val(v[j][0]);
        arr[1]=val(v[j][1]);
        arr[n-1]=val(v[j][2]);
        int f=1;
        for(int i=0; i<n; i++)
        {
            int l=i-1,r=i+1;
            if(l<0)
                l=n-1;
            if(r==n)
                r=0;
            if(arr[i]==1)
            {
                if(s[i]=='o')
                {

                    if(!arr[r])
                        arr[r]=arr[l];
                    else if(arr[r]!=arr[l])
                    {
                        f=0;
                        break;
                    }
                }
                else
                {
                    if(!arr[r])
                    {
                        if(arr[l]==1)
                            arr[r]=2;
                        else
                            arr[r]=1;
                    }
                    else if(arr[l]==arr[r])
                    {
                        f=0;
                        break;
                    }
                }
            }
            else
            {
                if(s[i]=='x')
                {
                    if(!arr[r])
                        arr[r]=arr[l];
                    else if(arr[r]!=arr[l])
                    {
                        f=0;
                        break;
                    }
                }
                else
                {
                    if(!arr[r])
                    {
                        if(arr[l]==1)
                            arr[r]=2;
                        else
                            arr[r]=1;
                    }
                    else if(arr[l]==arr[r])
                    {
                        f=0;
                        break;
                    }
                }
            }
        }
        if(f)
        {
            for(int i=0; i<n; i++)
            {

                if(arr[i]==1)
                    cout<<"S";
                else
                    cout<<"W";
            }
            cout<<endl;
            return 0;
        }
        for(int i=0; i<n; i++)
            arr[i]=0;
    }


    cout<<"-1"<<endl;



    return 0;
}


Measured memory_bytes: 4080
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
    
    int main() {
     int n;
     cin >> n;
     long int a[n];
     
     rep(i,n)	cin >> a[i];
     
     sort(a, a + n);
     
     long int sum = 0;
     
     rep(i,n)	sum+=a[i];
     cout << a[0] << ' ' << a[n-1] << ' ' << sum << '\n';
     return 0;
    }


Measured memory_bytes: 3216
#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-x))
#define int long long
using namespace std;
const int maxn = 2e5+5;
const int mod = 1e9+7;
const int i2 = 500000004;
int ad(int x,int y) { x+=y; return x>=mod?x-mod:x; }
int sb(int x,int y) { x-=y; return x<0?x+mod:x; }
int mu(int x,int y) { return 1ll*x*y%mod; }
void up(int &x,int y) { x+=y; if(x>=mod)x-=mod; }
int ksm(int a,int b) {
	int ans = 1;
	for(;b;b>>=1,a=mu(a,a))
		if(b&1) ans = mu(ans,a);
	return ans;
}
int n;
int bit[maxn],bnt[maxn];
void ins(int x,int d) {
	for(;x<=n;x+=lowbit(x)) 
		up(bit[x],d) , up(bnt[x],1);
}
int qe(int x) {
	int sm = 0;
	for(;x;x-=lowbit(x))
		up(sm,bit[x]);
	return sm;
}
int qn(int x) {
	int sm = 0;
	for(;x;x-=lowbit(x))
		up(sm,bnt[x]);
	return sm;
}
int a[maxn],cc[maxn],X[maxn];
int SS = 1,D[maxn],iD[maxn],ST[maxn];
main() {
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
		cc[a[i]]++;
	}
	for(int i=n-1;i>=1;i--) cc[i] += cc[i+1];
	for(int i=1;i<=n;i++) {
		cc[i] -= n-i;
		if(cc[i]<=0) {
			puts("0"); return 0;
		}
		SS = mu(SS,cc[i]);
	}
//	cerr<<SS<<endl;
	ST[0] = D[0] = 1;
	for(int i=1;i<=n;i++) {
		X[i] = X[i-1]; D[i] = D[i-1];
		int x = mu(cc[i]-1,ksm(cc[i],mod-2));
		if(!x) { X[i]++; ST[X[i]] = i;  }
		else D[i] = mu(D[i],x);
		iD[i] = ksm(D[i],mod-2);
	}
	int ans = 0;
	for(int i=1;i<=n;i++) {
		up(ans,mu(sb(qe(a[i]),qe(ST[X[a[i]]]-1)),mu(D[a[i]],mu(i2,SS))));
		ins(a[i],iD[a[i]]);
	}
	memset(bit,0,sizeof bit);
	memset(bnt,0,sizeof bnt);
	for(int i=n;i>=1;i--) {
		ans = sb(ans,mu(sb(qe(a[i]-1),qe(ST[X[a[i]]]-1)),mu(D[a[i]],mu(i2,SS))));
		ans = ad(ans,mu(qn(a[i]-1),SS));
		ins(a[i],iD[a[i]]);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define lli long long int
#define pb(a) push_back(a)
#define forr(a,n) for(lli i=a;i<n;i++)
#define forrr(j,a,n) for(lli j=a;j<n;j++)
#define all(x) x.begin(),x.end()
#define pi2  1.57079632679489661923
using namespace std;
void print(lli a[],lli n){
forr(0,n){cout<<a[i]<<" ";}
cout<<"\n";
}
lli power(lli x){
lli u=0;
while(x%2==0){
    u++;
    x=x/2;
}
return u;
}

lli powM(lli x,lli y,lli m)
{
    lli ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}
int powm(lli a, lli b) {
	lli res = 1;
	while (b) {
		if (b & 1)
			res = (res * a);
		a = (a * a);
		b >>= 1;
	}
	return res;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
/*
vector <lli> adj[100001];
lli vis[100001]={0};
void dfs(lli a){
    vis[a]=1;
    forr(0,adj[a].size()){
    if(vis[adj[a][i]]){continue;}
    else{
        dfs(adj[a][i]);
    }
    }
}
lli level[100001];
void bfs(lli a){
queue <lli> q;
vis[a]=1;
level[a]=0;
q.push(a);
while(!q.empty()){
    lli p=q.front();
    q.pop();
    forr(0,adj[p].size()){
    if(vis[adj[p][i]]==0){
        level[adj[p][i]]=level[p]+1;
        q.push(adj[p][i]);
        vis[adj[p][i]]=1;
    }
    }

}

}

vector <pair<lli,lli> > dj[100001];
lli dist[100001];
vector<lli> ans[100001];
void dijkstra(lli a){
dist[a]=0;
ans[a].pb(a);
multiset<pair<lli,lli> > s;
s.insert({0,a});
while(s.size()!=0){
    lli x=(*s.begin()).second;
    s.erase(s.begin());
    if(vis[x]){continue;}
    vis[x]=1;
    forr(0,dj[x].size()){
    lli e=dj[x][i].first;
    lli we=dj[x][i].second;
    if(dist[x]+we<dist[e]){
        dist[e]=dist[x]+we;
        ans[e].clear();
        ans[e].pb(x);
        s.insert({dist[e],e});
    }
    }
}

}*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
   cout.tie(0);
   // freopen("outpu.txt","w",stdout);
int t1=1;
//cin>>t1;
lli M =1e9+7;
while(t1--){
lli a;
cin>>a;
cout<<(a+a*a+a*a*a);
}
     return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka


int main() {
    std::ios::sync_with_stdio(false);

    string s;
    cin >> s;
    int k;
    cin >> k;
    int n = s.length();

    int d[n + 1][n + 1][k + 1];

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int kk = 0; kk <= k; kk++) {
                if (i == 0 || j == 0) {
                    d[i][j][kk] = 0;
                } else {
                    if (s[i - 1] == s[n - j]) {
                        d[i][j][kk] = d[i - 1][j - 1][kk] + 1;
                    } else {
                        d[i][j][kk] = std::max(d[i - 1][j][kk], d[i][j - 1][kk]);
                        if (kk > 0) {
                            d[i][j][kk] = std::max(d[i][j][kk], d[i - 1][j - 1][kk - 1] + 1);
                        }
                    }
                }
            }
        }
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
        res = std::max(res, d[i][n - i - 1][k] * 2 + 1);
        res = std::max(res, d[i][n - i][k] * 2);
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 106752
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll n;
    ll p[20];
    ll answer = 0;

    cin >> n;
    rep(i, n) cin >> p[i];

    rep(i, n - 2){
        if (p[i] < p[i + 1] && p[i + 1] < p[i + 2]) answer ++;
        else if (p[i] > p[i + 1] && p[i + 1] > p[i + 2]) answer ++;
    } 

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=5e5;
typedef int fuko[yuzu|10];
struct node {
  int l,r,id;
  void rd(int x) {
    read(l),read(r),id=x;
  }
}qr[yuzu|10];
fuko c,cnt,lxy;
int main() {
  int i,n,q,bk;
  read(n),read(q),bk=sqrt(n);
  for (i=1;i<=n;++i) c[i]=read();
  for (i=1;i<=q;++i) qr[i].rd(i); 
  sort(qr+1,qr+q+1,[&](node a,node b){return a.l/bk^b.l/bk?a.l<b.l:a.r<b.r;});
  int nl=1,nr=0,ans=0;
  for (i=1;i<=q;++i) {
    for (;nr<qr[i].r;) !cnt[c[++nr]]++?++ans:0;
    for (;nr>qr[i].r;) !--cnt[c[nr--]]?--ans:0;
    for (;nl<qr[i].l;) !--cnt[c[nl++]]?--ans:0;
    for (;nl>qr[i].l;) !cnt[c[--nl]]++?++ans:0;
    lxy[qr[i].id]=ans;
  } 
  for (i=1;i<=q;++i) printf("%d\n",lxy[i]);
}

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



int main(){
  ll n,V;
  cin>>n>>V;
  
  ll A[N],B[N],C[N],D[N];
  for(int i=0;i<n;i++)cin>>A[i];
  for(int i=0;i<n;i++)cin>>B[i];
  for(int i=0;i<n;i++)cin>>C[i];
  for(int i=0;i<n;i++)cin>>D[i];
  
  unordered_map<ll,ll> M1,M2;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)M1[A[i]+B[j]]++;

  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)M2[(C[i]+D[j])]++;
  
  ll ans=0;
  for(unordered_map<ll,ll>::iterator I=M1.begin();I!=M1.end();I++)
    ans+=I->second*M2[V-I->first];
  cout<<ans<<endl; 
  return 0;
}

Measured memory_bytes: 121416
n = int(input())
w = [str(input()) for i in range(n)]
hatugen = [w[0]]
for i in range(1,n):
    if w[i-1][-1] == w[i][0]:
        if w[i] in hatugen:
            print("No")
            exit()
        else:
            hatugen.append(w[i])
    else:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 38384
n = int(input())
ac, wa, tle, re = 0, 0, 0, 0
for i in range(n):
    s = input()
    if s == 'AC':
        ac += 1
    elif s == 'WA':
        wa += 1
    elif s == 'TLE':
        tle += 1
    else:
        re += 1
print('AC x', ac)
print('WA x', wa)
print('TLE x', tle)
print('RE x', re)

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

struct union_find{
    vector<ll> parent;
    vector<ll> nums;
    union_find(ll n){
        parent.resize(n);
        nums.resize(n, 1LL);
        rep(i, 0, n) parent[i] = i;
    }

    ll root(ll x){
        if(parent[x] == x) return x;
        parent[x] = root(parent[x]);
        return parent[x];
    }

    void unite(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx != ry){
            parent[rx] = ry;
            nums[ry] += nums[rx];
        }
    }

    bool same(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return true;
        return false;
    }

    ll size(ll x){
        return nums[root(x)];
    }
};  

int main(){
    ll N, M;
    cin >> N >> M;
    union_find T(N+1);
    vector<ll> p(N+1);
    rep(i, 1, N+1) cin >> p[i];
    rep(i, 1, M+1){
        ll x, y;
        cin >> x >> y;
        T.unite(x, y);
    }
    vector<ll> r(N+1);
    rep(i, 1, N+1) r[i] = T.root(i);
    ll ans = 0;
    rep(i, 1, N+1){
        if(T.same(p[i], i)) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>

int p[1002][1002][3];
int sum[1002][1002][3];

int main(void)
{
	int M, N, K;
	int a, b, c, d;
    char in[1001];
	int x, y, k;
    int j, o, i;
    int s;

	scanf("%d%d%d", &M, &N, &K);

   	memset(p, 0, sizeof(p));

	for (y = 1; y <= M; y++){
        scanf("%s", in);
		for (x = 1; x <= N; x++){
            if (in[x - 1] == 'J'){
                p[y][x][0] = 1;
            }
            else if (in[x - 1] == 'O'){
                p[y][x][1] = 1;
            }
            else {
                p[y][x][2] = 1;
            }
//printf("<%d %d %d>", p[y][x][0],p[y][x][1],p[y][x][2]);

		}
//printf("\n");
	}
	
	memset(sum, 0, sizeof(sum));

	for (y = 1; y <= M; y++){
		for (x = 1; x <= N; x++){
    		for (k = 0; k <= 2; k++){
    			sum[y][x][k] = sum[y - 1][x][k] + sum[y][x - 1][k] - sum[y - 1][x - 1][k] + p[y][x][k];
    		}
//printf("[%d %d %d]", sum[y][x][0],sum[y][x][1],sum[y][x][2]);
		}
//printf("\n");
	}

    for (k = 0; k < K; k++){
        scanf("%d%d%d%d", &b, &a, &d, &c);
        
        j = sum[d][c][0] - sum[d][a - 1][0] - sum[b - 1][c][0] + sum[b - 1][a - 1][0];
        o = sum[d][c][1] - sum[d][a - 1][1] - sum[b - 1][c][1] + sum[b - 1][a - 1][1];
        i = sum[d][c][2] - sum[d][a - 1][2] - sum[b - 1][c][2] + sum[b - 1][a - 1][2];
        
        printf("%d %d %d\n", j, o, i);
    }  

    return (0);
}

Measured memory_bytes: 24136
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	long MODULO = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] t = new int[n];
		int[] p = new int[n];
		int[] x = new int[s];
		for (int i = 0; i < s; ++i) {
			x[i] = sc.nextInt();
		}
		for (int i = 0; i < n; ++i) {
			t[i] = sc.nextInt();
			p[i] = sc.nextInt();
			--p[i];
		}
		int[] w = new int[n];
		for (int i = 0; i < n; ++i) {
			w[i] = t[i] - x[p[i]];
		}
		Arrays.sort(w);
		long ans = 0;
		for (long v : w) {
			ans -= v;
		}
		long[][] f = new long[n + 1][m + 1];
		for (int i = 0; i < f.length; ++i) {
			for (int j = 0; j < f[i].length; ++j) {
				f[i][j] = Integer.MAX_VALUE / 16;
			}
		}
		for (int i = 1; i < f.length; ++i) {
			f[i][1] = w[i - 1] * i;
		}

		for (int j = 2; j <= m; ++j) {
			// j is fixed???
			// Attention: h[i][k]:=f[k][j-1]+w[i-1]*(i-k) is of Monge.
			// min(h[i][]) can be enumerated in O(n*log(n))
			// f[i][j]=min(h[i][])
			long[] v = calc(f, w, j);
			for (int i = 1; i <= n; ++i) {
				// for (int k = 1; k <= i - 1; ++k) {
				// f[i][j] = Math.min(f[i][j], h(f, w, i, j, k));
				// }
				f[i][j] = v[i];
			}
		}

		long min = Integer.MAX_VALUE / 16;
		for (int j = 1; j <= m; ++j) {
			min = Math.min(min, f[n][j]);
		}
		ans += min;
		System.out.println(ans);
	}

	long[] calc(long[][] f, int[] w, int j) {
		int n = f.length - 1;
		int m = f[0].length - 1;
		long[] ret = new long[n + 1];
		Arrays.fill(ret, Integer.MAX_VALUE / 16);
		rec(ret, 1, n, 2, n + 1, f, w, j);
		return ret;
	}

	// [low,high)
	// [left,right)
	long rec(long[] ret, int low, int high, int left, int right, long[][] f, int[] w, int j) {
		int mid = (left + right) / 2;// the value of the variable i
		long v = Long.MAX_VALUE / 16;
		int arg = -1;
		for (int k = Math.max(0, low); k <= Math.min(mid - 1, high); ++k) {
			v = Math.min(v, h(f, w, mid, j, k));
			if (v == h(f, w, mid, j, k))
				arg = k;
		}
		if (right - left > 1) {
			rec(ret, low, arg, left, mid, f, w, j);
			rec(ret, arg, high, mid, right, f, w, j);
		}
		ret[mid] = v;
		return v;
	}

	long h(long[][] f, int[] w, int i, int j, int k) {
		return f[k][j - 1] + w[i - 1] * (i - k);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 79744
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

# 8方向
directions = ((1,0),(-1,0),(0,1),(0,-1),(1,1),(-1,-1),(-1,1),(1,-1))
cnt = 0

def rec(cur, prev):

    global cnt
    h, w = cur // (W+2), cur % (W+2)
    if visited[h][w]:
        return
    visited[h][w] = 1
    # 初回のみ、島カウントを足す
    if prev == -1:
        cnt += 1

    for d in directions:
        h2, w2 = h + d[0], w + d[1]
        if grid[h2][w2]:
            rec(h2*(W+2)+w2, cur)
    return 

while True:

    W, H = MAP()
    if H == W == 0:
        break

    grid = list2d(H+2, W+2, 0)
    for i in range(1, H+1):
        row = LIST()
        for j in range(1, W+1):
            grid[i][j] = row[j-1]

    visited = list2d(H+2, W+2, 0)
    cnt = 0
    for i in range(1, H+1):
        for j in range(1, W+1):
            if grid[i][j]:
                rec(i*(W+2)+j, -1)
    print(cnt)



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

int main(){
    int N, M;
    cin >> N >> M;
    int ans = 0;
    vector<int> H(N);
    rep(i, N){
        cin >> H.at(i);
    }
    vector<int> A(M);
    vector<int> B(M);
    rep(i, M){
        cin >> A.at(i) >> B.at(i);
    }
    vector<int> C(N, 0);
    rep(i, M){
        if(H.at(A.at(i) - 1) < H.at(B.at(i) - 1)){
            C.at(A.at(i) - 1)++;
        } else if(H.at(A.at(i) - 1) > H.at(B.at(i) - 1)){
            C.at(B.at(i) - 1)++;
        } else {
            C.at(A.at(i) - 1)++;
            C.at(B.at(i) - 1)++;
        }
    }
    rep(i, N){
        if(C.at(i) == 0){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4804
import sys
sys.setrecursionlimit(10 ** 6)

def main():
    s=input()
    n=len(s)
    i=0
    pre="X"
    cnt=0
    while i<n:
        if pre==s[i]:
            if i==n-1:
                break
            else:
                i+=2
                pre="X"
        else:
            pre=s[i]
            i+=1
        cnt+=1
    print(cnt)

main()

Measured memory_bytes: 3500
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i > (b); i--)

using namespace std;

int N;
int H[105];

int main(void) {
    scanf("%d", &N);
    REP(i, 0, N) scanf("%d", &H[i]);

    int max = H[0];
    int ans = 0;
    REP(i, 0, N) {
    	if ( H[i] >= max ) {
    		ans++;
    		max = H[i];
    	}
    }
    
    printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int A, B; cin >> A >> B;

  int retval = -1;
  rep(i,2000){
    int a = (i*8)/100;
    int b = (i*10)/100;
    if (a==A && b==B) {
      retval = i;
      break;
    }    
  }
  cout << retval << endl;



  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 256
from collections import Counter

def solve():
    N = int(input())
    if N == 0:
        return False
    *S, = map(int, input().split())
    cnt = 0
    while 1:
        c = Counter(S)
        *T, = map(c.__getitem__, S)
        if S == T:
            break
        S = T
        cnt += 1
    print(cnt)
    print(*S)
    return True
while solve():
    ...



Measured memory_bytes: 5992
N=int(input())
C=list(map(int,input().split()))
mod=10**9+7
C.sort(reverse=True)

ans=pow(2,N-1,mod)*C[0]
ans%=mod
for i in range(1,N):
    ans+=(pow(2,N-1,mod)+i*pow(2,N-2,mod))*C[i]
    ans%=mod

ans*=pow(2,N,mod)
ans%=mod
print(ans)


Measured memory_bytes: 87500
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;


int main() {
	string s;
	cin >> s;
	int n = s.size();
	int a = 101, b = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'C' && i < a)
			a = i;
		else if (s[i] == 'F' && i > b)
			b = i;
	}
	if (a < b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;

    switch (n % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon" << endl;
        break;

    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon" << endl;
        break;

    case 3:
        cout << "bon" << endl;
        break;

    default:
        break;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll a, b, x;
  cin >> a >> b >> x;
  ll s = (a - 1) / x;
  if(a==0){
    s = -1;
  }
  ll t = b / x;
  print(t - s);
}

Measured memory_bytes: 256
def main():
    s = list(map(int, list(input())))
    m = [0]*2019
    num = 0
    ans = 0
    n = len(s)
    ten = 1
    for i in range(n):
        num += s[n-i-1]*ten
        num %= 2019
        m[num] += 1 
        ten = (ten*10)%2019
    for mi in m:
        if mi:
            ans += (mi*(mi-1))//2
    ans += m[0]
    print(ans)
        
if __name__ == "__main__":
    main()

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

int main() {
  int H,W;
  scanf("%d %d", &H,&W);
  string board[50];
  for(int i=0;i<H;++i) cin >> board[i];

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

  bool flag;
  bool final = false;

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (board[i][j] == '.') continue;

      flag = false;

      for (int d=0;d<4;++d){
        const int ni = i + dy[d];
        const int nj = j + dx[d];

        if(ni<0 or ni>=H) continue;
        if(nj<0 or nj>=W) continue;
        if(board[ni][nj]=='#'){
          flag = true;
          break;
        }
      }

      if(!flag){
        final = true;
        break;
      }
    }
  }

  if(final) cout << "No" << endl;
  else cout << "Yes" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

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

  ll dp[n + 1][n] = {};
  ll cum[n] = {};

  REP(j, n) { dp[1][j] = 1; }
  cum[0] = dp[1][0];
  FOR(j, 1, n) { cum[j] = cum[j - 1] + dp[1][j]; }

  FOR(i, 2, n + 1) {
    REP(j, n - i + 1) {
      if (s[i - 2] == '<') {
        dp[i][j] = (cum[n - i + 1] - cum[j] + MOD) % MOD;
      } else {
        dp[i][j] = cum[j] % MOD;
      }
      // cout << i << " " << j << " " << dp[i][j] << endl;
    }
    cum[0] = dp[i][0];
    FOR(j, 1, n - i + 1) { cum[j] = (cum[j - 1] + dp[i][j]) % MOD; }
  }

  ll ans = 0;
  REP(j, n) { ans = (ans + dp[n][j]) % MOD; }
  cout << ans << endl;
}


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

using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    int N;
    cin >> N;
    Graph G(N);
    vector<int>deg(N,0);
    vector<bool>f(N,false);
    for(int i = 0; i < N; i++)
    {
        int u,v;
        cin >> u >> v;
        u--,v--;
        G[u].push_back(v);
        G[v].push_back(u);
        deg[u]++;
        deg[v]++;
    }
    queue<int>que;
    for(int i = 0; i < N; i++)
    {
        if(deg[i] == 1)
        {
            f[i] = true;
            que.push(i);
        }
    }
    while(!que.empty())
    {
        int v = que.front();
        que.pop();
        for(auto nv: G[v])
        {
            if(f[nv]) continue;
            --deg[nv];
            if(deg[nv] == 1)
            {
                que.push(nv);
                f[nv] = true;
            }
        }
    }
    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++)
    {
        int a,b;
        cin >> a >> b;
        a--,b--;
        if(f[a]||f[b]) cout << 1 << endl;
        else cout << 2 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 8696
using System;
    using System.Text;
    using System.Collections.Generic;
    using static System.Math;
    using System.Linq;
    using static System.Array;
    
    namespace ConsoleApp2
    {
    class Program
    {
        static string S;
        static void Main(string[] args)
        {

            //var N = long.Parse(Console.ReadLine());
            var NK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var N = NK[0];
            var K = NK[1];

            var ans = 1L;

            foreach (var item in GetDivisors(K))
            {
                if((K/item) >= N)
                {
                    ans = Max(item, ans);
                }
            }

            //var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

            //var minI = -1L;
            //for (int i = 0; i < N; i++)
            //{
            //    if (A[i] == 1) {
            //        minI = i;
            //        break;
            //    }
            //}


            //var ans = (minI+1) / (K-1);
            //if (minI > 0 && K - 1 > minI) minI = Min(K - 1, N - 1);
            ////ans += (N - 1 - minI) / (K - 1);

            //while (N-1 > minI)
            //{
            //    minI += K - 1;
            //    ans++;
            //}


            Console.WriteLine(ans);
            
            

            
        }

        public static IEnumerable<long> GetDivisors(long num)
        {
            if (num < 1) yield break;

            for (long i = 1; i * i <= num; i++)
            {
                if (num % i == 0)
                {
                    yield return i;
                    if (i * i != num) yield return (num / i);
                }
            }
        }
    }
}


Measured memory_bytes: 13396
package main

import (
	"fmt"
)

func isMatch(a, b []string, m, x, y int) bool {
	match := true
	for i := 0; i < m; i++ {
		for j := 0; j < m; j++ {
			if a[x+i][y+j] != b[i][j] {
				match = false
			}
		}
	}
	return match
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	a := make([]string, n)
	b := make([]string, m)
	for i := range a {
		fmt.Scan(&a[i])
	}
	for i := range b {
		fmt.Scan(&b[i])
	}

	ok := false
	for i := 0; i <= n-m; i++ {
		for j := 0; j <= n-m; j++ {
			ok = ok || isMatch(a, b, m, i, j)
		}
	}

	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
n, m = map(int,input().split())
a = [-1]*n
for i in range(m):
    s, c = map(int,input().split())
    if n > 1:
        if s == 1 and c == 0:
            print(-1)
            exit()
    if a[s-1] >= 0:
        if a[s-1] != c:
            print(-1)
            exit()
    else:
        a[s-1] = c

if n == 1:
    if a[0] == -1:
        print(0)
    else:
        print(a[0])
    exit()
    
ans = ''
for i, t in enumerate(a):
    if i == 0 and t == -1:
        ans += '1'
    elif t == -1:
        ans += '0'
    else:
        ans += str(t)
print(ans)


Measured memory_bytes: 3064
program sample
implicit none
integer N,K,d(100),A(100,100),i,j,B(100),count1
read(*,*) N,K
count1=0
do i=1,K
read(*,*) d(i)
read(*,*)(A(i,j),j=1,d(i))
end do
B=0
do i=1,K
do j=1,d(i)
B(A(i,j))=A(i,j)
end do
end do
do i=1,N
if (B(i)==0) then
count1=count1+1
end if
end do
write(*,*) count1
stop
end program sample

Measured memory_bytes: 2856
from typing import Callable


class DynamicProgramming(object):

    table: list
    obj_coef: list
    sbj_coef: list

    def __init__(self, item_n: int, border: int):
        self.item_n = item_n
        self.border = border

    def __str__(self):
        return "\n".join(list(map(lambda l:
                                  " ".join(list(map(str, l)))
                                  , self.table)))

    def __repr__(self):
        return "DynamicProgramming object:\n" + \
               "item_n: " + str(self.item_n) + ", border: " + str(self.border) + "\n" +\
               "table:\n" + self.__str__()

    def solve(self, obj_coef: list, sbj_coef: list, expr: Callable[[int, int], int], initializer=0) -> list:
        self.table = [[initializer for _ in range(self.item_n + 1)] for _ in range(self.border + 1)]

        if len(obj_coef) == self.item_n:  # to 1-base
            obj_coef = [None] + obj_coef
        self.obj_coef = obj_coef

        if len(sbj_coef) == self.item_n:
            sbj_coef = [None] + sbj_coef
        self.sbj_coef = sbj_coef

        for weight_lim in range(1, self.border + 1):
            for item_idx in range(1, self.item_n + 1):
                self.table[weight_lim][item_idx] = expr(weight_lim, item_idx)

        return self.table

    def knapsack_expr(self, weight_lim: int, item_idx: int) -> int:
        res = self.table[weight_lim][item_idx - 1]
        if weight_lim - self.sbj_coef[item_idx] >= 0:
            res = max(res, self.table[weight_lim - self.sbj_coef[item_idx]][item_idx - 1] + self.obj_coef[item_idx])
        return res


if __name__ == '__main__':
    N, W = map(int, input().split())
    v, w = [], []
    for i in range(N):
        buff = [int(j) for j in input().split()]
        v.append(buff[0])
        w.append(buff[1])

    dp = DynamicProgramming(N, W)
    print(dp.solve(v, w, dp.knapsack_expr)[W][N])



Measured memory_bytes: 28200