akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int M[200][200];
string color[200];
int d[200];
int f[200];
int t = 0;
int n;

void dfs(int u){
    color[u] = "GRAY";
    d[u] = ++t;
    for (int i = 0; i < n; i++){
        if(M[u][i] && color[i] == "WHITE"){
            dfs(i);
        }
    }
    color[u] = "BLACK";
    f[u] = ++t;
}

void dfs_init(){
    rep(i, n){
        color[i] = "WHITE";
    }
    rep(i, n){
        if(color[i] == "WHITE"){
            dfs(i);
        }
    }
}

int main() {
    cin >> n;
    rep(i, n){
        int a, b; cin >> a >> b;
        rep(j, b){
            int x; cin >> x;
            x--;
            M[i][x] = 1;
        }
    }
    dfs_init();
    rep(i, n){
        cout << i+1 << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3244
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int x[114514];
int main()
{
	int n,A,B;lint a,b,out=0;
	scanf("%d %d %d",&n,&A,&B);
	a=A;b=B;
	rep(i,n) scanf("%d",&x[i]);
	rep(i,n-1){
		lint d=x[i+1]-x[i];
		out+=min(d*a,b);
	}
	cout<<out<<endl;
}


Measured memory_bytes: 640
/* This Code Is Nude */
#include <bits/stdc++.h>
     
#define pb push_back
#define ll long long
#define int long long
 
using namespace std;
     
const ll inf = 1e12 + 10;
const int maxn = 2e5 + 10;
const int MOD = 998244353;
 
int a[maxn];
 
int32_t main(){
	int n , k;
	int md = 0;
	int im[2];
	cin >> k >>n;
	for(int i = 0 ; i < n ; i++){
		cin >> a[i];
	}
	im[0] = n-1;
	im[1] = 0; 
	md = (k - a[n - 1]) + a[0];
	for(int i = 1 ; i < n ; i++){
		if(md < a[i] - a[i-1]){
			md = a[i] - a[i-1];
		}
	}
	int ans = (k - a[n - 1]) + a[0];
	for(int i = 1 ; i < n ; i++)
		ans += a[i] - a[i-1]; 
	cout << ans - md << endl;
	return 0;
}


Measured memory_bytes: 1792
def isPrime(n):
  if n < 2:
    # 2未満は素数でない
    return False
  if n == 2:
    # 2は素数
    return True
  for p in range(2, n):
      if n % p == 0:
        # nまでの数で割り切れたら素数ではない
        return False
  # nまでの数で割り切れなかったら素数
  return True

X = int(input())
flg = True
ans = 0
while flg:
  if isPrime(X):
    flg = False
    ans = X
  X +=1
print(ans)

Measured memory_bytes: 38384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ; 
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 2e5 + 5 ; 
const ll inf = 1e17 + 7 ;
using namespace std ;

int n, m, A, B, x[N] ;
ll bit[2][2][N], dist[N], f[2][N] ;

void put(int cx, int cy, int x, ll y) {
	for ( ; x <= n ; x += x & (- x)) bit[cx][cy][x] = min(bit[cx][cy][x], y) ;
}

ll get(int cx, int cy, int x) {
	ll res = inf ;
	for ( ; x ; x -= x & (- x)) res = min(res, bit[cx][cy][x]) ;
	return res ;
}

int main() {
	scanf("%d%d%d%d", &n, &m, &A, &B) ;
	rep(i, 1, m) scanf("%d", &x[i]) ;
	rep(i, 0, 1) rep(j, 0, 1) rep(k, 1, n) bit[i][j][k] = inf ;
	rep(i, 2, m) dist[i] = dist[i - 1] + abs(x[i] - x[i - 1]) ;
	f[0][0] = abs(B - x[1]), f[1][0] = abs(A - x[1]) ;
	put(0, 0, A, f[0][0] - dist[1] - A), put(0, 1, n - A + 1, f[0][0] - dist[1] + A) ;
	put(1, 0, B, f[1][0] - dist[1] - B), put(1, 1, n - B + 1, f[1][0] - dist[1] + B) ;
	rep(i, 1, m - 1) {
		f[0][i] = min(get(1, 0, x[i + 1]) + dist[i] + x[i + 1], get(1, 1, n - x[i + 1] + 1) + dist[i] - x[i + 1]) ;
		f[1][i] = min(get(0, 0, x[i + 1]) + dist[i] + x[i + 1], get(0, 1, n - x[i + 1] + 1) + dist[i] - x[i + 1]) ;
		put(0, 0, x[i], f[0][i] - dist[i + 1] - x[i]), put(0, 1, n - x[i] + 1, f[0][i] - dist[i + 1] + x[i]) ;
		put(1, 0, x[i], f[1][i] - dist[i + 1] - x[i]), put(1, 1, n - x[i] + 1, f[1][i] - dist[i + 1] + x[i]) ;
	}
	ll ans = inf ;
	rep(i, 0, m - 1) ans = min(ans, min(f[0][i], f[1][i]) + dist[m] - dist[i + 1]) ;
	printf("%lld\n", ans) ;
	return 0 ;
}

Measured memory_bytes: 11904
#include<stdio.h>
#include<string.h>
int main(void){
  char str[200],cop1[100],cop2[100];
  int i,j,k,l;
  scanf("%s",str);
  for(i=(strlen(str)-1);i>2;i--){
    for(j=0;j<(i/2);j++){
      cop1[j]=str[j];
    }
    cop1[i/2]='\0';
    for(j=(i/2),k=0;j<i;j++,k++){
      cop2[k]=str[j];
    }
    cop2[i/2]='\0';
    if(strcmp(cop1,cop2)==0){
      printf("%d",i-1);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 128
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 K              PIC 9(10).
01 S              PIC X(100).

PROCEDURE DIVISION.
  ACCEPT K.
  ACCEPT S.
  IF K < FUNCTION STORED-CHAR-LENGTH(S)
      DISPLAY S(1 : K) "..."
  ELSE
      DISPLAY FUNCTION TRIM(S)
  END-IF.
  STOP RUN.


Measured memory_bytes: 3784
// author: Wenxing Mei
//   date: 2018-06-10 20:43
//     ac: 2018-06-10 20:43
#include <bits/stdc++.h>
using namespace std;

int main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
#endif
    vector<int> a{1};
    for (int i = 6; i <= 100000; i *= 6) a.push_back(i);
    for (int i = 9; i <= 100000; i *= 9) a.push_back(i);
    sort(a.begin(), a.end());
    // for (int x : a) cout << x << endl;

    int n;
    scanf("%d", &n);

    int left = 1, right = 1000, mid;
    function<int(int, int, int)> check = [&](int ind, int use, int v) -> int {
        if (v == 0) return 1;
        if (ind == 0) return use >= v;
        if (use * a[ind] < v) return 0;
        // printf("%d check %d %d %d\n", mid, ind, use, v);
        for (int i = 0; i <= use && i * a[ind] <= v; ++i) {
            if (check(ind - 1, use - i, v - i * a[ind])) return 1;
        }
        return 0;
    };

    while (left < right) {
        mid = (left + right + 1) / 2;
        // cout << left << " " << mid << " " << right << endl;
        if (check(a.size() - 1, mid, n))
            right = mid - 1;
        else
            left = mid;
    }

    printf("%d\n", check(a.size() - 1, right, n) ? right : right + 1);

    return 0;
}

Measured memory_bytes: 256
#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 repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,v) VL v(n);rep(i,n)cin>>v[i]
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define LINE puts("------------------")
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
typedef struct{ll to;ll cost;} Graphs;
typedef V<V<Graphs>> AdjList;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}

template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<class T>T center(T a,T b,T c){
  if( (a<=b&&b<=c)||(a>=b&&b>=c) )return b;
  if( (b>=a&&a>=c)||(b<=a&&a<=c) )return a;
  return c;
}
void print(){cout<<endl;}
template<class Head,class... Tail>
void print(Head&& head, Tail&&... tail){
  cout<<head<<", ";
  print(forward<Tail>(tail)...);
}
void input(){}
template<class Head,class... Tail>
void input(Head&& head, Tail&&... tail){
  cin>>head;
  input(forward<Tail>(tail)...);
}
template<typename T>
ostream &operator<<(ostream&out,const vector<T>&v){
  if(!v.empty()){
    copy(v.begin(),v.end(),ostream_iterator<T>(out,", "));
    out<<"\b\b";
  }
  return out;
}
template<typename T1, typename T2>
ostream &operator<<(ostream&out,const pair<T1,T2>&p){
  out<<p.first<<", "<<p.second;
  return out;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  ll n,k;
  input(n,k);
  if(k==0){out(n*n);return 0;}
  ll ans=0;
  for(int b=k+1;b<=n;++b){
    ll tmp=n/b;
    tmp*=(b-k);
    tmp+=max(0LL,n%b-k+1);
    ans+=tmp;
  }
  out(ans);


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<queue>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=1000000000LL;
typedef long long ll;
typedef pair<int,int> Q;
typedef pair<int,Q> Pa;
ll N,A[100005],D[2][8005]={},B[200005]={};
ll L[55],ans=0;
int xy[2];
int kx[4]={1,0,-1,0},ky[4]={0,-1,0,1};
int h=0;
int hk[2];
string s;
bool dp[2][8000][16000]={};
bool reg(int n,int k,ll v){
	if(dp[n][k][v])return false;
	if(k==hk[n]){
		if(v==xy[n])return true;
		return false;
	}
	if(reg(n,k+1,v+D[n][k])||reg(n,k+1,v-D[n][k]))return true;
	dp[n][k][v]=true;
	return false;
}

int main(){
	cin>>s>>xy[0]>>xy[1];
	for(int i=0;i<s.size();++i){
		if(s[i]=='T')h++;
		else D[h%2][h/2]++;
	}
	h++;
	hk[0]=h/2+h%2;
	hk[1]=h/2;
	if(reg(0,1,D[0][0])&&reg(1,0,0)){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 64384
y500 = int(input())
y100 = int(input())
y50 = int(input())
ysum = int(input())
count = 0

for a in range(y500+1):
  for b in range(y100+1):
    for c in range(y50+1):
      if ysum == a*500 + b*100 + c*50:
        count += 1

print(count)

Measured memory_bytes: 3060
n, m, c = list(map(int, input().split()))
b = list(map(int, input().split()))

ac = 0

for _ in range(n):
	res = c
	a = list(map(int, input().split()))
	for x, y in zip(a, b):
		res += x * y
	
	if res > 0:
		ac += 1

print(ac)

Measured memory_bytes: 9120
from math import sqrt

n = int(input())
vector1 = map(int,input().split())
vector2 = map(int,input().split())
diffs = [abs(x-y) for x,y in zip(vector1,vector2)]
print (sum(diffs))
print (sqrt(sum(map(lambda n:pow(n,2),diffs))))
print ((sum(map(lambda n:pow(n,3),diffs)))**(1/3))
print (max(diffs))

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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; i++)
#define repn(i, st, ed) for(ll i=st; i<=ed; i++)
#define repb(i, ed, st) for(ll i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code
ll ppow(ll x, ll y, ll mod)
{
  ll res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%mod;
    y = y >> 1;
    x = (x * x)%mod;
  }
  return res;
}

int main()
{
	string s;
	ll ans = 1;
	cin>>s;
	repb(i, s.length()-1, 0)
	{
		if(s[i] == '0') continue;
		ans = (ppow(3, s.length()-1-i, M) + (2* ans) % M ) % M;
	}	
	cout<<ans<<endl;
}


Measured memory_bytes: 512
def tenchi(gr):
    gr_t=[[0]*len(gr) for i in range(len(gr[0]))]
    for i in range(len(gr)):
        for j in range(len(gr[i])):
            gr_t[j][i] = gr[i][j]
    return gr_t

H, W = map(int,input().split())
a=[list(input()) for i in range(H)]
#yoko
while a.count(["."]*len(a[0]))>0:
    a.remove(["."]*len(a[0]))

a_t = tenchi(a)
while a_t.count(["."]*len(a_t[0]))>0:
    a_t.remove(["."]*len(a_t[0]))
ans = tenchi(a_t)
for i in range(len(ans)):
    ansa = "".join(ans[i])
    print(ansa)

Measured memory_bytes: 3316
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
  [n, m] <- readInts
  ass <- sortOn last <$> replicateM m readInts
  print $ solve 0 ass

readInts :: IO [Int]
readInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

solve :: Int -> [[Int]] -> Int
solve _ [] = 0
solve p ([a, b]:ass)
  | a >= p
    = succ $! solve b ass
  | a < p
    = solve p ass


Measured memory_bytes: 57724
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
//#define long long ll;
 
int main(){
 
 long long m,n;
 cin>>n>>m;
 
  vector<long long>v;
 
 
    int sum =0;
 for(int i=0,x;i<n;i++){
    cin>>x;
    v.push_back(x);
     sum += x; }
 
 
    sort(v.begin(),v.end());
    int cnt=0;
   for(int i=0;i<n;i++){
    if( (v[i] * 4*m) >= sum)
        cnt++;
   }
 
   if(cnt >=m)
    cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
 
  return 0;
  }


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll x,a;
    cin>>x>>a;
    if(x<a){
        cout<<0<<endl;
    }else{
        cout<<10<<endl;
    }
}


Measured memory_bytes: 256
ans = 0
R, G, B, N = map(int, input().split())
rl = (N+R-1)//R+1
gl = (N+G-1)//G+1
bl = (N+B-1)//B
for r in range(rl):
  for g in range(gl):
    tmp = N - (r*R) - (g*G)
    if tmp < 0:
      break
    if tmp == 0:
      ans += 1
    elif tmp%B == 0 and tmp%B <= bl:
      ans += 1
print(ans)

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

bool comp(int a, int b){
    return (a<b);
}

int main(){
    string s; cin >> s;
    int i = 0;
    string flg = "Yes";
    do{
        if(i%2==1){
            if(s[i]!='L' && s[i]!='U' && s[i]!='D') flg = "No";
        }else{
            if(s[i]!='R' && s[i]!='U' && s[i]!='D') flg = "No";
        }
        i++;
    }while(flg=="Yes" && i<s.length()-1);
    cout << flg << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long int ll;

int main() {
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll cost[n]={0};
	cost[1]=abs(a[1]-a[0]);
	for(ll i=2;i<n;i++){
		cost[i]=min(cost[i-1]+abs(a[i]-a[i-1]),cost[i-2]+abs(a[i]-a[i-2]));
	}
	ll min=INFINITY;
	cout<<cost[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1792
n, *AB = map(int, open(0).read().split())
a = sorted(AB[::2])
b = sorted(AB[1::2])
if n % 2 == 0:
	print(b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2] + 1)
else:
	print(b[(n + 1) // 2 - 1] - a[(n + 1) // 2 - 1] + 1)

Measured memory_bytes: 55372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;
ll INF = 1e12+10;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
vector<pair<ll, ll> > pairs;

const ll MAX = 10000000000 * 300 + 10;
ll dp[310][310];
int main()
{
    ll N, K, tmp;
    cin >> N >> K;
    vector<ll> H(N + 2);
    rep(i, N)cin >> H[i + 1];
    H[0] = H[N + 1] = 0;
    
    //rep(i, N)cout << H[i + 1]  << endl;
    for (int i = 1; i <= N; i++){
        dp[0][i] = MAX;
        //dp[i][0] = 0;
    }
    dp[0][0] = 0;
    for (int i = 1; i <= N; i++){
        for (int j = 1; j <= N; j++){
            tmp = MAX;
            for (int i0 = 0; i0 < i; i0++){
                if (j - 1 == 0){
                    tmp = H[i];
                } else {
                    tmp = min(tmp, dp[i0][j - 1] + max(0LL, H[i] - H[i0]));
                }
                //fprintf(stderr, "i0 = %d, tmp = %d\n", i0, tmp);
            }
            dp[i][j] = tmp;
            //cout << i << " " << j << " " << tmp << endl;
            //fprintf(stderr, "dp[%d][%d] = %Ld\n", i, j, tmp);
        }
    }
    ll ans = MAX;
    for (int i = 1; i <= N; i++){
        ans = min(ans, dp[i][N - K]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, k; cin >> n >> k;
	ll ans = 0;
	ll p = 1;
	while (p <= n) {
		ans++;
		p *= k;
	}
	cout << ans << endl;
	return 0;
}

/*
3
0 1
3 0
1 0
*/

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

int main() {
	long long a, b, n, ans;
	cin >> n;
	cin >> a >> b;

	if (a + b == 0) {
		cout << 0 << endl;
		return 0;
	}

	long long sur = n % (a + b);
	long long quo = n / (a + b);

	if (quo == 0) {
		ans = min(a, sur);
	}
	else {
		ans = a * quo + min(a, sur);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) { (cin >> A[i]), A[i] = i - A[i]; }
    vector<int> r(N, 0);
    int maxi = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] < maxi or A[i] > i) { return (cout << -1 << endl), 0; }
        maxi = max(maxi, A[i]);
        r[A[i]] = i - A[i];
    }
    cout << accumulate(r.begin(), r.end(), 0LL) << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


ll x[100010], v[100010];
ll hlf[100010];
ll ret[100010];
ll rev_hlf[100010];
ll rev_ret[100010];

int main(){
    int n;
    ll c;
    cin >> n >> c;
    rep(i, n) cin >> x[i] >> v[i];

    ll cal = 0;
    rep(i, n){
        cal += v[i];
        hlf[i] = cal - x[i];
        ret[i] = cal - 2 * x[i];
    }

    cal = 0;
    rrep(i, n){
        cal += v[i];
        rev_hlf[i] = cal - (c - x[i]);
        rev_ret[i] = cal - 2 * (c - x[i]);
    }

    rep(i, n-1) hlf[i+1] = max(hlf[i], hlf[i+1]);
    rep(i, n-1) ret[i+1] = max(ret[i], ret[i+1]);
    rrep(i, n-1) rev_hlf[i] = max(rev_hlf[i], rev_hlf[i+1]);
    rrep(i, n-1) rev_ret[i] = max(rev_ret[i], rev_ret[i+1]);


    // rep(i, n) cout << hlf[i] << " " << ret[i] << endl;

    ll ans = 0;

    rep(i, n){ // i : turn point
        ans = max(ans, hlf[i]);
        if(i < n-1) ans = max(ans, ret[i] + rev_hlf[i+1]);
        ans = max(ans, rev_hlf[i]);
        if(i > 0) ans = max(ans, hlf[i] + rev_ret[i+1]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8332
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll H, W;
    cin >> H >> W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }
    if ((H * W) % 2 == 0) {
        cout << H * W / 2 << endl;
    } else {
        cout << (H * W) / 2 + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
///In the name of Almighty Allah(swt).

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll a,result,i,j;
    cin>>a;
    i = a*a;
    j = i*a;
    result = a+i+j;
    cout<<result<<endl;

    return 0;
}



Measured memory_bytes: 3604
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;

int main(){
  ll n, k, s;
  cin>>n>>k>>s;
  rep(i,k) std::cout << s << ' ';
  if(k==n) return 0;
  if (s == 1000000000) {
    rep(i,n-k-1) std::cout << s-1 << ' ';
    std::cout << s-1 << std::endl;
  } else {
    rep(i,n-k-1) std::cout << s+1 << ' ';
    std::cout << s+1 << std::endl;
  }
  return 0;
}


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

int main(){
  ll n, a, b, c, tmp;
  cin >> n;
  a=b=c=0;
  ll ans=1;
  ll count=0;
  for(int i=0; i<n; i++){
    count = 1;
    cin >> tmp;
    if(a==tmp){
      a++;
      if(b==tmp){count++;}
      if(c==tmp){count++;}
    }else if(b==tmp){
      b++;
      if(c==tmp){count++;}
    }else if(c==tmp){c++;}
    else{cout << 0 << endl;return 0;}
    if(1>count||3<count){cout << 0 << endl;return 0;}
    ans = (ans%1000000007)*count;
  }
  cout << ans%1000000007 << endl;
}
    
      
  

Measured memory_bytes: 384
#include<iostream>
using namespace std;
void dfs(int,int);
int box[52][52];
int main(){
  int w,h,i,I,a;
  while(1){
    a=0;
    cin>>w>>h;
    if(w==0&&h==0) break;
    for(i=0;i<=h+1;i++){
      for(I=0;I<=w+1;I++){
	box[i][I]==0;
      }
    }
    for(i=1;i<=h;i++){
      for(I=1;I<=w;I++){
	cin>>box[i][I];
      }
    }
    for(i=1;i<=h;i++){
      for(I=1;I<=w;I++){
	if(box[i][I]==1){
	  dfs(i,I);
	  a++;
	}
      }
    }
    cout<<a<<endl;
  }
  return 0;
}
  void dfs(int i,int I){
  if(box[i][I]==0) return;
  box[i][I]=0;
  dfs(i,I+1);
  dfs(i+1,I+1);
  dfs(i+1,I);
  dfs(i+1,I-1);
  dfs(i,I-1);
  dfs(i-1,I-1);
  dfs(i-1,I);
  dfs(i-1,I+1);
  }

Measured memory_bytes: 1272
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	lnt n;
	std::cin >> n;
	lnt ans=0;
	for(lnt i=1;i<=n;i++) {
		for(lnt j=1;j*i<=n;j++) {
			ans+=i*j;
		}
	}
	print(ans);
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <stdlib.h>

void max(int *pa, int *pb, int *pc) {
  if (*pa >= *pb && *pa >= *pc) {  // a is max
    ; // do nothing
  } else if (*pb >= *pa && *pb >= *pc) {  // b is max
    int tmp = *pa;
    *pa = *pb;
    *pb = tmp;
  } else {  // c is max
    int tmp = *pa;
    *pa = *pc;
    *pc = tmp;
  }
}

int main(int argc, char *argv[]) {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  // printf("%d %d %d\n", a, b, c);
  max(&a, &b, &c);
  // printf("%d %d %d\n", a, b, c);
  printf("%d\n", 10 * a + b + c);
  return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

	static int h, w;
	static char[][] board;
	
	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		h=fs.nextInt(); w=fs.nextInt();
		int sy=fs.nextInt()-1, sx=fs.nextInt()-1;
		int ey=fs.nextInt()-1, ex=fs.nextInt()-1;
		ArrayDeque<Integer> xs=new ArrayDeque<>(), ys=new ArrayDeque<>();
		board=new char[w][h];
		for (int y=0; y<h; y++) {
			char[] line=fs.next().toCharArray();
			for (int x=0; x<w; x++) {
				board[x][y]=line[x];
			}
		}
		xs.add(sx);
		ys.add(sy);
		int[][] dist=new int[w][h];
		for (int x=0; x<w; x++) Arrays.fill(dist[x], 1_000_000_000);
		dist[sx][sy]=0;
		int[] dx= {-1, 1, 0, 0};
		int[] dy= {0, 0, -1, 1};
		while (!xs.isEmpty()) {
			int curX=xs.removeFirst(), curY=ys.removeFirst();
			for (int d=0; d<4; d++) {
				int nx=curX+dx[d], ny=curY+dy[d];
				if (!legal(nx, ny)) continue;
				if (dist[nx][ny]>dist[curX][curY]) {
					dist[nx][ny]=dist[curX][curY];
					xs.addFirst(nx);
					ys.addFirst(ny);
				}
			}
			for (int x=curX-2; x<=curX+2; x++) {
				for (int y=curY-2; y<=curY+2; y++) {
					if (!legal(x, y)) continue;
					if (dist[x][y]>dist[curX][curY]+1) {
						dist[x][y]=dist[curX][curY]+1;
						xs.addLast(x);
						ys.addLast(y);
					}
				}
			}
		}
		System.out.println(dist[ex][ey]>1e7?-1:dist[ex][ey]);
	}

	static boolean legal(int x, int y) {
		if (x<0||y<0||x>=w||y>=h || board[x][y]=='#') return false;
		return true;
	}
	
	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


Measured memory_bytes: 65616
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 1e5+10;
 ll mod = 1e9+7;


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> a_s(n);
  rep(i,n){ 
    int input = 0;
    cin >> input;
    a[i] = input;
    a_s[i] = input;
  } 
  sort(rall(a_s));
  for(int i=0;i<n;i++){
    if(a_s[0] != a[i]) cout << a_s[0] << endl;
    else cout << a_s[1] << endl;
  }
}

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

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

    long long ans = pow(10, 18);
    ans = min(((A - A / 2) - A / 2) * B * C, ans);
    ans = min(((B - B / 2) - B / 2) * C * A, ans);
    ans = min(((C - C / 2) - C / 2) * A * B, ans);
    cout << ans << endl;
}

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

//写経C++
//https://atcoder.jp/contests/abc147/submissions/8852580

using namespace std;
typedef long long ll;
typedef pair<int,int> II;

int main(void)
{
    int n;
    int c[100] = {0};

    scanf("%d",&n);
    for(int i=0;i<n;++i){
        ll x;
        scanf("%lld",&x);
        for(int j=0;j<60;j++){
            c[j] += x>>j & 1;
        }
    }

    const int MOD = (int)1e9+7;
    int ans =0;
    int mul = 1;
    for(int i=0;i<60;i++){
        int val = (ll)c[i]*(n-c[i])%MOD;
        ans = (ans + (ll)val * mul)%MOD;
        mul = mul *2 %MOD;
    }

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

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	int n; cin>>n; n%=10;
	if(n==2||n==4||n==5||n==7||n==9)cout<<"hon\n";
	if(n==0||n==1||n==6||n==8)cout<<"pon\n";
	if(n==3)cout<<"bon\n";
}

Measured memory_bytes: 3668
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=2e5+5;
int n,val[N];
lint sum;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	template <class T> inline T cabs(const T &x){return x<0?-x:x;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	n=nxi();
	for(int i=1; i<=n; ++i){
		val[i]=nxi();
		sum+=val[i];
	}
	lint ans=2e15,tmp=0;
	for(int i=1; i<n; ++i){
		tmp+=val[i];
		apn(ans,cabs(tmp-(sum-tmp)));
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
S=int(input())

N=int(S/3)
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
n = 10 ** 4  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p) 階乗のmod
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, n + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


ans=0
for i in range(1,N+1):
    now=3*i
    if i==1:
        ans+=1
        continue
    res=S-now
    ans+=cmb(i-1+res, res, p)
    ans%=p
print(ans)

Measured memory_bytes: 67748
#include <cstdio>
#include <cstring>
#include <stack>
#include <algorithm>
using namespace std;

const int MAX_N     = 100000;
const int UNKNOWN   = -1;

struct op {
  char op;
  int target;

  bool isMark() {
    return op == 'M';
  }

  bool isQuery() {
    return op == 'Q';
  }
};

int data[MAX_N + 1];

struct UnionFind {
  void init() {
    for (int i = 0; i <= MAX_N; i++) {
      data[i] = UNKNOWN;
    }
  }

  void unite(int x, int y) {
    x = root(x), y = root(y);
    if (x != y) {
      data[x] = y;
    }
  }

  int root(int x) {
    return data[x] < 0 ? x : root(data[x]);
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }
};

UnionFind uf;
stack<op> ops;
int marked[MAX_N + 1];
int p[MAX_N + 1];

int main()
{
  while (true) {
    int N, Q; scanf("%d%d", &N, &Q);
    if (N == Q && Q == 0) break;

    uf.init();

    memset(marked, false, sizeof marked);
    p[0] = 0; p[1] = 1;
    for (int i = 2; i <= N; i++) {
      scanf("%d", p + i);
    }

    for (int i = 0; i < Q; i++) {
      op op;
      scanf(" %c%d", &op.op, &op.target);
      if (op.isMark() && !marked[op.target]) {
          marked[op.target] = true;
          ops.push(op);
      }
      else if (op.isQuery()) {
        ops.push(op);
      }
    }

    for (int i = 1; i <= N; i++) {
      if (!marked[i]) {
        uf.unite(i, p[i]);
      }
    }

    long long ans = 0;
    while (!ops.empty()) {
      op op = ops.top(); ops.pop();

      if (op.isMark()) {
        uf.unite(op.target, p[op.target]);
      }
      else {
        ans += uf.root(op.target);
      }
    }

    printf("%lld\n", ans);
  }
  return 0;
}


Measured memory_bytes: 4444
import java.util.*;

public class Main {
	Scanner sc;
	int K, X;
	public Main() {
		sc = new Scanner(System.in);
	}
	
	private void calc() {
		K = sc.nextInt();
		X = sc.nextInt();
		
		int min = X-(K-1);
		int max = X+(K-1);
		if (min < -1000000) min = -1000000;
		if (max > 1000000) max = 1000000;
		
		for (int i = min; i <= max; i++) {
			System.out.print(i);
			if (i < max) System.out.print(" ");
		}
		System.out.println();
		System.out.flush();
	}
	
	public static void main(String[] args) {
		Main m = new Main();
		m.calc();
	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
using namespace std;

int n;
long long x[210],k[210],a[210];

long long findsg(int x,int k)
{
	if (x<k) return 0;
	if (x%k==0) return x/k;
	if (k>=100000)
	{
		long long op=x-k*(x/k);
		long long oq=op%(x/k+1);
		x=k*(x/k)+oq;
		if (oq==0) return x/k;
		return findsg(x-x/k-1,k);
	}
	else
	return findsg(x-x/k-1,k);
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&x[i],&k[i]);
		a[i]=findsg(x[i],k[i]);
	}
	long long ans=0;
	for (int i=1;i<=n;i++)
	{
		ans=ans^a[i];
	}
	if (ans!=0) printf("Takahashi\n");
	else printf("Aoki\n");
}

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

const int mod = (1e9) + 7;

void multiply(int n, vector<vector<int>>& a, vector<vector<int>>& b) {
	vector<vector<int>> ans(n, vector<int>(n, 0));
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j < n; j ++) {
			for(int k = 0; k < n; k ++) {
				ans[i][j] += a[i][k]*b[k][j];
				ans[i][j] %= mod;
			}
		}
	}
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j < n; j ++) {
			a[i][j] = ans[i][j]%mod;
		}
	}
}
void solve() {
	int n, k; cin >> n >> k;
	vector<vector<int>> g(n, vector<int>(n, 0));
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j < n; j ++) {
			cin >> g[i][j];
		}
	}
	vector<vector<int>> ans(n, vector<int>(n, 0));
	for(int i = 0; i < n; i ++) {
		ans[i][i] = 1;
	}
	while(k) {
		if(k&1) {
			multiply(n, ans, g);
		}
		multiply(n, g, g);
		k >>= 1;
	}
	int total = 0;
	for(auto i:ans) {
		for(auto j:i) {
			total += j;
			total %= mod;
		} 
	}
	cout << total%mod << endl;
}

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

	int t = 1;  
	// cin >> t;
	while(t --) {
		solve();
	}
	return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



string s;
void solve(){
	cin >> s;
	int n = s.size();
	
	bool a = 0, b = 0,c = 0, d = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'N'){
			a = 1;
		}
		if(s[i] == 'W'){
			b = 1;
		}
		if(s[i] == 'S'){
			c = 1;
		}
		if(s[i] == 'E'){
			d = 1;
		}
	}
	if(!(a^c) && !(b^d)) cout << "Yes" << endl;
	else cout << "No" << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

int main() {
ll m,n ;
  cin>>m>>n;
  if(m>=3&&n>=3){
  cout<<m*n-(2*m+2*n-4);}
  else if(m==2&&n==2){
    cout<<0<<endl;}
  else if(m==2||n==2){
    cout<<0<<endl;}
  else if(m==1&&n==1){
    cout<<1<<endl;}
  else cout<<m*n-2<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    aa,bb = map(int, input().split())
    a.append((aa,bb))

push = 0
for i in range(n-1, -1, -1):
    if (a[i][0] + push) % a[i][1] != 0:
        push += a[i][1] -  (a[i][0] + push) % a[i][1]
print(push)


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

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


int main(){
    int n;
    cin>>n;
    
    vector<int> a(n);
    
    int j=0;
    rep(i,n){
        cin>>a.at(i);
        if(a.at(i)%2!=0)continue;
        else{
            if(a.at(i)%3==0||a.at(i)%5==0){
                continue;
            }else{
                j=1;
                break;
            }
        }
    }
    
    if(j==1){
        cout<<"DENIED"<<endl;
    }else{
        cout<<"APPROVED"<<endl;
    }
    
    
    
    
}

Measured memory_bytes: 256
n=int(input())
if n < 10 :
    print(n)
else:
    n=list(str(n))
    key=0
    for i in range(len(n)-1):
        if n[1+i]!="9":
            key=1
    if key ==0:
        print((len(n)-1)*9+int(n[0]))
    else:
        print((len(n)-1)*9+int(n[0])-1)



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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;


class DSU{
   public:
   vector <int> id , sz;
   DSU(int n){
      id.resize(n+1);
      sz.resize(n+1);
      for(int i=0 ; i<=n ; i++){
         id[i] = i;
         sz[i] = 1;
      }
   }

   int root(int i){
      while(i != id[i])   id[i] = id[id[i]] , i = id[i];
      return i;
   }

   void uni(int a, int b){
      int ra = root(a);
      int rb = root(b);
      if(ra == rb)   return;
      if(sz[ra] < sz[rb]) swap(ra,rb);
      id[rb] = ra , sz[ra] += sz[rb];
   }
};

int32_t main() {
   fast;
   int n,m;
   cin >> n >> m;

   DSU ds(n+1);

   f(i,0,m){
      int u,v;
      cin >> u >> v;
      ds.uni(u,v);
   }

   set<int> s;
   f(i,1,n+1)  s.insert(ds.root(i));
   int ans = sz(s) - 1;

   cout << ans << "\n";
}

Measured memory_bytes: 8408
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        l: u32,
        r: u32,
    }

    if r - l >= 2019 || l % 2019 >= r % 2019 {
        println!("0");
    }else {
        let mut ans = 2020;
        for i in l..r {
            if i % 2019 == l % 2019 && i != l {
                break;
            }
            for j in l + 1..r + 1 {
                if j % 2019 == (l + 1) % 2019 && j != (l + 1) {
                    break;
                }
                ans = ans.min(((i % 2019) * (j % 2019)) % 2019);
                if ans == 0 {
                    break;
                }
            }
            if ans == 0 {
                break;
            }
        }
        println!("{}", ans);
    }
}


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

using namespace std;
#define ll long long
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1e9 + 7;

int main (){
    int n;
    cin >> n;
    vector<char> vec(n + 100);
    REP(i,n){
        cin >> vec.at(i);
    }
    vector<int> vec1(26);
    REP(i,n){
        vec1.at(vec.at(i) - 'a')++;
    }
    long long ans = 1;
    REP(i,26){
        ans *= (vec1.at(i) + 1);
      	ans %= mod;
    }

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

Measured memory_bytes: 384
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;

class UnionFind {
private:
	vector<int> par;
public:
	UnionFind(int N) { par = vector<int>(N, -1LL); }
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};



class Kruskal {
private:
	UnionFind *uf;
	vector<edge> e;
public:
	vector<edge> mst;
	Kruskal(int N) { uf = new UnionFind(N); }
	void add(int x, int y, ll z);
	void run();
};



//----UnionFind-------------------------------
int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}

ll UnionFind::size(int x) {
	return -par[find(x)];
}

void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);

	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}



//----Kruskal-------------------------------
void Kruskal::add(int x, int y, ll z) {
	//x < y
	if (x > y) swap(x, y);
	e.push_back({ z,{x,y} });
}

void Kruskal::run() {
	sort(e.begin(), e.end());
	e.erase(unique(e.begin(), e.end()), e.end());
	for (auto x : e) {
		if (uf->same(x.second.first, x.second.second)) {
			continue;
		}
		else {
			mst.push_back(x);
			uf->unite(x.second.first, x.second.second);
		}
	}
}



signed main() {
	int n;
	cin >> n;
	int a[n];
	REP (i,n) {
		cin >> a[i];
	}
	int ans = 0;
	REP (i,n) {
		if (i < a[i]-1) {
			if (i + 1 == a[a[i]-1]) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
n = str(input())
if n[-1] == "2" or n[-1] == "4" or n[-1] == "5" or n[-1] == "7" or n[-1] == "9":
    print("hon")
elif  n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8":
    print("pon")
else:
    print("bon")

Measured memory_bytes: 8936
n = gets.to_i
h = gets.split.map(&:to_i)

dp = []
dp[0] = 0
dp[1] = (h[0] - h[1]).abs
(2...n).each do |i|
  dp[i] = [
    dp[i - 1] + (h[i - 1] - h[i]).abs,
    dp[i - 2] + (h[i - 2] - h[i]).abs
  ].min
end
puts dp[n - 1]


Measured memory_bytes: 11396
// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
    return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
    return n = n | (1LL << pos);
}

ll perp[5003];
ll c[5003];
pll vis[5003];

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n >> m)
    {
        for(ll i = 1; i <= n; i++)
        {
            cin >> perp[i];
        }

        for(ll i = 1; i <= n; i++)
        {
            cin >> c[i];
        }

        ans = mnlld;
        for(ll i = 1; i <= n; i++) vis[i] = {mnlld, 0};

        for(ll i = 1; i <= n; i++)
        {
			ll cycle = 0;
			ll full = 0;

			ll now = i;

			if(vis[i].first != mnlld)
			{
				full = vis[i].first;
				cycle = vis[i].second;
			}
			else
			{
				while(1)
				{
//					cout << now << " " << perp[now] << endl;
					now = perp[now];
					full += c[now];
					cycle++;

					assert(cycle <= n);

					if(now == i) break;
				}

//				bug;

				while(1)
				{
					now = perp[now];

					assert(vis[now].first == mnlld);

					vis[now] = {full,cycle};

					assert(cycle <= n);

					if(now == i) break;
				}

			}


            ll rem = m % cycle;
            ll totcost = (m / cycle) * full;

            if(m >= cycle) ans = max(ans, totcost);
            if(rem == 0) rem += cycle, totcost -= full;

            totcost = max(totcost, 0LL);
            now = i;

            for(ll j = 0; j < rem; j++)
            {
                now = perp[now];

                totcost += c[now];

                ans = max(ans, totcost);
            }

            totcost = 0;
            now = i;

            for(ll j = 0; j < min(cycle, m); j++)
            {
				now = perp[now];

				totcost += c[now];

				ans = max(ans, totcost);
            }

//			cout << endl;
        }

        cout << ans << "\n";
    }


}






Measured memory_bytes: 3792
import java.util.Scanner;

public class Main{
	
	static int LCS(String a, String b) {
		int max = Math.max(a.length(), b.length());
		int[][] array = new int[max + 1][max + 1];
		int m = a.length();
		int n = b.length();
		int MAX = 0;
		a = ' ' + a;
		b = ' ' + b;
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= n; j++) {
				if (a.charAt(i) == b.charAt(j)) {
					array[i][j] = array[i - 1][j - 1] + 1;
				} else {
					array[i][j] = Math.max(array[i - 1][j], array[i][j - 1]);
				}
				MAX = Math.max(MAX, array[i][j]);
			}
		}
		return MAX;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for(int i=0; i<n; i++) {
			String s1 = in.next();
			String s2 = in.next();
			System.out.println(LCS(s1, s2));
		}
	}

}





Measured memory_bytes: 65708