akhauriyash/Code-Regression huggingface dataset:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------
dx = [1,0,-1,0]
dy = [0,1,0,-1]

def BFS(dq):
    while dq:
        e = dq.popleft()
        y,x = e
        for i in range(4):
            yi = y+dy[i]
            xi = x+dx[i]
            if 0<=yi<Y and 0<=xi<X:
                if A[yi][xi] != "#" and A[yi][xi] == ".":
                    A[yi][xi] = A[y][x] + 1 
                    dq.append((yi,xi))


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
H,W = map(int,input().split())
S = [list(input().rstrip()) for _ in range(H)]

Y,X = H,W
A = S

A[0][0] = 1
from collections import deque
dq = deque([(0,0)])
BFS(dq)

if A[Y-1][X-1] == ".":
    print(-1)
else:
    cnt = 0
    for a in A:
        cnt += a.count("#")
    print(X*Y - cnt - A[Y-1][X-1])

Measured memory_bytes: 3316
#include<cstdio> 
#include<algorithm>  
#include<iostream>  
#include<string>  
#include<cmath>  
using namespace std;
typedef long long ll;
const ll inf=1<<29;
const ll Maxn=1e6;
 
ll A[Maxn],B[Maxn],C[Maxn];
 
int main(){
	ll a,b,c,x;
	ll q=0,w=0,e=0,mid=0;
	cin>>a>>b>>c>>x;
	for(int i=1;i<=a;i++) A[++q]=500*i;
	for(int i=1;i<=b;i++) B[++w]=100*i;
	for(int i=1;i<=c;i++) C[++e]=50*i;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(A[i]+B[j]+C[k]==x) mid++;
			}
		}
	}
	printf("%lld\n",mid);
}

Measured memory_bytes: 4984
#include <iostream>

using namespace std;

#define N_MAX 3001

int p;
int a[3000];

int inv[N_MAX],fac[N_MAX],finv[N_MAX];

int W, B, N;

void init(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=p-inv[p%i]*(p/i)%p;
        fac[i]=fac[i-1]*(int) i%p;
        finv[i]=finv[i-1]*inv[i]%p;
    }
}

int comb(int n, int r){
  int ans;
  if(n < r){
      ans = 0;
  }else{
      ans = (fac[n]*finv[r])%p;
      ans = (ans*finv[n-r])%p;
      ans = (ans+p)%p;
  }
  return ans;
}

int ans[3000];

int main(){
    
    cin >> p;
    init();
    for(int i = 0; i < p; i++){
        cin >> a[i];
        if(a[i] == 1){
            ans[0] += 1;
            int pow = 1;
            for(int j = p-1; j >= 0; j--){
                ans[j] -= (comb(p-1, j)*pow)%p;
                ans[j] %= p;
                ans[j] += p;
                ans[j] %= p;
                pow *= (-i);
                pow %= p;
                pow += p;
            }
        }
    }
    for(int i = 0; i < p-1; i++){
        cout << ans[i] << ' ';
    }
    cout << ans[p-1] << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
bool p[100000];
int cnt[100000];
int main()
{
	int n,m;
	ll tmp=0;
	ll ans=0;
	cin>>n>>m;
	fill(p,p+100000,false);
	fill(cnt,cnt+100000,0);
	for(int i=0;i<m;i++)
	{
		int pr;string s;
		cin>>pr>>s;
		pr--;
		if(s=="AC" && !p[pr])
		{
			tmp++;
			ans+=cnt[pr];
			p[pr]=true;
		}
		if(s=="WA")
			cnt[pr]++;
	}
	cout<<tmp<<" "<<ans<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>

int main(void)
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a==1) a+=13;if(b==1) b+=13;
    if(a>b) printf("Alice");
    else if(a<b) printf("Bob");
    else printf("Draw");
    return 0;
}


Measured memory_bytes: 128
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1

def main():
    to = defaultdict(set)
    ot = defaultdict(set)
    n, m = map(int, input().split())
    cnt_in_degree = [0] * n
    parent = [-1] * n
    for _ in range(n + m - 1):
        a, b = map(int1, input().split())
        cnt_in_degree[b] += 1
        to[a].add(b)
        ot[b].add(a)
    root = cnt_in_degree.index(0)
    parent[root] = -1
    part_roots = [root]
    cnt_decide = 1
    while cnt_decide < n:
        u = part_roots.pop()
        for ku in to[u]:
            if len(ot[ku]) == 1:
                parent[ku] = u
                part_roots.append(ku)
                cnt_decide += 1
            else:
                ot[ku].remove(u)
    for u in parent:
        print(u + 1)

main()


Measured memory_bytes: 69552
#include <iostream>

using namespace std;

long long n, ans=1, a[1005];
void f(int p) {
    int i;
    for(i=2; p>1; ) {
        if(p % i == 0) {
            a[i]++;
            p /= i;
        } else {
            i++;
        }
    }
}

int main()
{
    int i;
    cin >> n;
    for(i=2; i<=n; i++) {
        f(i);
    }
    for(i=2; i<=n; i++) {
        ans = ans * (a[i]+1) % 1000000007;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>

int main (void) {
long long int A,B,K;
scanf("%lld %lld %lld",&A,&B,&K);
long long int reste = K-A;
if (reste>0) {B=B-reste;
              if (B<0) B=0;
              A=0; }
else if (reste<0) {A=A-K;}
else if (reste==0) {A=0;}
printf("%lld %lld",A,B);

return EXIT_SUCCESS;
}


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

typedef long long ll;

int main() {
    // input
    int N;
    cin >> N;
    map<ll, int> A;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        A[a]++;
    }

    // solve
    ll ans = 0, tmp = 0;
    vector<ll> v;
    vector<ll> v2;
    for (auto itr = A.begin(); itr != A.end(); ++itr) {
        if (itr->second >= 4) {
            v.push_back(itr->first);
        }
        if (itr->second >= 2) {
            v2.push_back(itr->first);
        }
    }
    if (v2.size() != 0) {
        sort(v2.begin(), v2.end());
        ans = v2[v2.size() - 1] * v2[v2.size() - 2];
    }
    if (v.size() != 0) {
        sort(v.begin(), v.end());
        tmp = v[v.size() - 1] * v[v.size() - 1];
    }
    ans = max(ans, tmp);

    // output
    cout << ans << endl;

    return 0;
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;
typedef std::queue<long> QI;
#define rep(i,n) for(long i = 0; i < (long)n; ++i)
const double pi = M_PI;
const long mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      std::string ss; scan(ss);
      long n = ss.size();
      long x = ss.size() - 2;
      for(long i = 1; i < n - 1; ++i) {
         if( ss[i-1] != ss[i+1] ) {
            break;
         }
         x -= 1;
      }
      for(long i = n - 2; i >= 1; --i) {
         if( ss[i-1] != ss[i+1] ) {
            break;
         }
         x -= 1;
      }
      if( x <= 0 ) {
         puts("Second");
         return;
      }
      puts((ss.size() + (ss[0] == ss[n-1] ? 1 : 0)) % 2 == 0 ? "Second" : "First");
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
long double EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////////////////

int main(){fastio;
    ll n,k;cin>>n>>k;
    ll a[n],b[n];rep(i,0,n-1)cin>>a[i]>>b[i];
    ll p=0;
    ll ans=0;
    for(ll i=30;i>=0;i--){
        if(k&(1ll<<i)){
            p+=(1<<i)-1;
            ll sum=0;
            rep(j,0,n-1){
                if((p&a[j])==a[j])sum+=b[j];
            }
            Max(ans,sum);
            //cout<<p<<" "<<sum<<endl;
            p++;
        }
    }
    p=k;ll sum=0;
    rep(j,0,n-1){
        if((p&a[j])==a[j])sum+=b[j];
    }
    Max(ans,sum);
    cout<<ans<<endl;
    
    return 0;
}







Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  vector<char> vec(4);
  for (auto &v : vec)
    cin >> v;
  sort(vec.begin(), vec.end());
  if (vec[0] == vec[1] && vec[2] == vec[3] && vec[1] != vec[2])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = if n <= m then  List.range n `To m else []
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'
let itoa n = Char.chr (n + Char.code '0')

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (n,k) = scan "%d %d" Tuple2.make
let ls = scan_list ~sep:' ' Int.of_string

let () =
  List.sort Int.compare ls
  |> List.take k
  |> List.sum
  |> Printf.printf "%d\n"


Measured memory_bytes: 5776
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();

        if(x - r < 0 || x + r > W) {
            System.out.println("No");
        }
        else if(y - r < 0 || y + r > H) {
            System.out.println("No");
        }
        else {
            System.out.println("Yes");
        }

    }
}



Measured memory_bytes: 26412
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
   int n;
   cin >> n;
   vector<int> v(n+1);
   vector<int> u(n);
   rep(i,n+1) cin >> v[i];
   rep(i,n) cin >> u[i];
   ll ans = 0;
   rep(i,n){
      if (v[i] - u[i] > 0) {
         ans+=ll(u[i]);
         v[i] -= u[i];
         u[i] = 0;
      }
      else{
         ans+=ll(v[i]);
         u[i] -= v[i];
         v[i] = 0;
      }

      if (v[i+1] - u[i] > 0) {
         ans+=ll(u[i]);
         v[i+1] -= u[i];
         u[i] = 0;
      }
      else{
         ans+=ll(v[i+1]);
         u[i] -= v[i+1];
         v[i+1] = 0;
      }
      //cout << i << " " << ans << endl;
      //rep(i,n) cout << u[i];
      //cout << endl;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String str = reader.readLine();
			int x = Integer.parseInt(str);
			System.out.println(x * x * x);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}

Measured memory_bytes: 24360
/******************************************
* AUTHOR : AAYUSH GARG*
* NICK : aayushgarg_03 *
* INSTITUTION : BIT MESRA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define dd double
#define ld long double
#define for0(i, n) for(ll i = 0; i < n; i++)
#define for2(a,b,c) for(ll i=a;i<b;i+=c)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define VP vector< pii >
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define ascii(c) (int)char (c)
#define all(v) (v).begin(),(v).end()
#define Sort(v) sort(v.begin(), v.end(), sortbysec)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define N 1000000
ll inf=1e18;
ll prime[N];

ll mulmod(ll a, ll b, ll m) 
{ 
    ll res = 0;  
    a = a % m; 
    while (b > 0) 
    { 
       
        if (b % 2 == 1) 
            res = (res + a) % m; 
  
        
        a = (a * 2) % m; 
  
        
        b /= 2; 
    } 
  
    return res % m; 
} 

ll modInverse(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        
        ll q = a / m; 
        ll t = m; 
  
        m = a % m, a = t; 
        t = y; 
  
        
        y = x - q * y; 
        x = t; 
    } 
  
    
    if (x < 0) 
       x += m0; 
  
    return x; 
} 

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;  
  
    while (y > 0) 
    { 
        
        if (y & 1) 
            res = (res*x) % p; 
  
         
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
}

void sieve() {
    for(ll i = 0;i < N;i++)
        prime[i] = 1;
    prime[0] = 0;
    prime[1] = 0;
    for(ll i = 2;i*i < N;i++) {
        if(prime[i] == 0)
            continue;
        for(ll j = i*i;j < N;j+=i) {
            prime[j] = 0;
        }
    }
    for(ll i = 1;i < N;i++)
        prime[i] += prime[i-1];
}



bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 

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

ll n,k;
cin>>n>>k;
ll a[n];
ll dp[n];
for0(i,n){
 cin>>a[i];
 dp[i] = inf;
}


dp[0] = 0;




for(ll i=1;i<n;i++){
	 
	 for(ll j=i-1;j>=max(i-k,(ll)(0));j--)
	 {
	 	dp[i] = min(dp[i],dp[j] + abs(a[i]-a[j]));
	 }
	 
}

cout<<dp[n-1]<<endl;

return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int per[100];
int per2[20];
int perB[100];

int perSize = 0;
int per2Size = 0;


ll a[SIZE];
ll ans = INF * 5LL;

void dfs(int n, int h = 0, int f = 0){  
  ans = min(ans, a[0] + a[1] + a[2] + a[3] + a[4] + h);
  
  for(int i=0;i<perSize;i++){
    if((f & perB[i]) == 0){
      for(int j=0;j<n;j++) a[j] -= !!(per[i] & (1 << j));
      
      if(a[0] >= 0 && a[1] >= 0 && a[2] >= 0 && a[3] >= 0 && a[4] >= 0)
        dfs(n, h+1, f | perB[i]);
      
      for(int j=0;j<n;j++) a[j] += !!(per[i] & (1 << j));
    }
  }
  
}

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

  for(int i=0;i<n;i++){
    scanf("%lld",a+i);
  }

  for(int i=0;i<(1<<n);i++){
    int p = __builtin_popcount(i);
    if(p < 2) continue;
    if(p == 2){
      per2[per2Size++] = i;
    }
    per[perSize++] = i;
  }

  for(int i=0;i<perSize;i++){
    for(int j=0;j<per2Size;j++){
      if((per[i] & per2[j]) == per2[j])
        perB[i] |= 1 << j;
    }
  }

  dfs(n);

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



Measured memory_bytes: 3236
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
vector<int> vertexs[300000];
int first_time = 1;
long long solve(long long now,long long back,long long k) {
	long long ans = 1;
	long long pre_k = k;
	if (first_time == 1) {
		pre_k += 2;
		first_time = 0;
		ans *= pre_k;
		pre_k--;
	}
	for (long long q = 0; q < vertexs[now].size(); ++q) {
		if (back == vertexs[now][q]) continue;
		ans *= pre_k;
		ans %= MAX_MOD;
		pre_k--;
		ans *= solve(vertexs[now][q], now, k);
		ans %= MAX_MOD;
	}
	return ans;
}
int main(){
	int n, k;
	cin >> n >> k;
	if (n == 1) {
		cout << k << endl;
		return 0;
	}
	else if (n == 2) {
		cout << k * (k - 1) << endl;
		return 0;
	}
	REP(i, n-1) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		vertexs[a].push_back(b);
		vertexs[b].push_back(a);
	}
	for (int i = 0; i < n; ++i) {
		if (vertexs[i].size() >= 2) {
			cout << solve(i,-1, k-2)%MAX_MOD << endl;
			return 0;
		}
	}

	assert(0 == 1);
}

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

int Linear(int x,int s[],int n){
  for(int i=0; i<n; i++){
    if(s[i]==x)
      return 1;
  }

  return 0;
}

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

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

  int q;
  cin >> q;

  int t[q];
  for(int i=0; i<q; i++){
    cin >> t[i];
  }

  int count=0;
  for(int i=0; i<q; i++){
    if(Linear(t[i],s,n)!=0){
      count++;
    }
  }

  cout << count << endl;

  return 0;
}



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

int main() {
   int n;
   cin >> n;
   int a,b,c;
   a=n*25/27;
   b=n*25%27;
   c=(a+1) *27 /25 ;
   
   string s = ":(";
   if(b==0&&n>=27)cout << a<<  endl;
   else  if(b!=0&& (a+1) *27 /25 == n ) cout << a+1 << endl;
   else cout <<s << endl;
}

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

namespace abc123_c
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = decimal.Parse(Console.ReadLine());
            var TL = new List<decimal>();
            
            for (int i = 0; i < 5; i++)
                TL.Add(decimal.Parse(Console.ReadLine()));

            if (TL.Min() == 1)
                Console.WriteLine(N - 1 + 5);
            else
                Console.WriteLine(Math.Floor(N / TL.Min()) + 5);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> x;
	vector<int> y;
	vector<int> num;
	vector<int> red;
	x.resize(M + 10);
	y.resize(M + 10);
	num.resize(N + 10);
	red.resize(N + 10);
	for (int n = 0; n < N; ++n) {
		num[n] = 1;
		red[n] = 0;
	}
	red[0] = 1;
	int j = 0;
	for (int n = 0; n < M; ++n) {
		cin >> x[n] >> y[n];
		x[n] = x[n] - 1;
		y[n] = y[n] - 1;
		if (red[x[n]] == 1) {
			red[y[n]] = 1;
		}
		num[x[n]] -= 1;
		num[y[n]] += 1;
		if (num[x[n]] == 0) {
			red[x[n]] = 0;
		}
	}
	for (int k = 0; k < N; ++k) {
		if (red[k])++j;
	}
	cout << j << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define per(i,n) for ((i)=n;(i)>=(1);(i)--)
using namespace std;
int n,m,i,j,cnt,fa[100005];
set<int> adj[100005];
queue<pair<int,int> > q;
int fnd(int x){
	if(fa[x]==x) return x;
	return fa[x]=fnd(fa[x]); 
}
int main(){
	scanf("%d",&n);
	rep(i,n) fa[i]=i;
	rep(i,n+n-2){
		int a,b;
		scanf("%d%d",&a,&b);
		if(adj[a].count(b)) q.push(make_pair(a,b));
		adj[a].insert(b);
		adj[b].insert(a);
	}
	while(!q.empty()){
		int x=q.front().first,y=q.front().second;q.pop();
		x=fnd(x);y=fnd(y);if(x==y) continue;
		if(adj[x].size()>adj[y].size()) swap(x,y);
		cnt++;fa[x]=y;adj[x].erase(y);adj[y].erase(x);
		for(set<int>::iterator it=adj[x].begin();it!=adj[x].end();it++){
			int t=fnd(*it);if(t==y) continue;
			adj[t].erase(x);
			if(adj[y].count(t)){
				q.push(make_pair(min(t,y),max(t,y)));
			}
			adj[y].insert(t);adj[t].insert(y);
		}
		adj[x].clear();
	}
	if(cnt>=n-1) puts("YES"); else puts("NO");
	return 0;
}

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

int N;
int k[100010];
bool been[100010];

int main()
{
	memset(been, 0, sizeof(been));
  ios::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> k[i];
	for (int i = 0; i < N - 1; i++)
	{
		if (k[i] > k[i + 1] && !been[i]) k[i]--, been[i] = 1;;
		if (k[i + 1] > k[i]) k[i + 1] --, been[i + 1] = 1;
	}
	for (int i = 0; i < N - 1; i++)
		if (k[i] > k[i + 1]) 
		{
			cout << "No" << endl;
			return 0;
		}
	cout << "Yes" << endl;
}


Measured memory_bytes: 768
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n, k;
    cin >> n >> k;
    vi a(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n-k){
        YN(a[i] < a[i + k]);
    }
}

Measured memory_bytes: 4848
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
struct edge{
    int to,cost;
    edge(int a,int b):to(a),cost(b){}
    edge(){}
    bool operator>(const edge &d)const{
        return cost>d.cost;
    }
};
int main(){
    int N,M;
    while(scanf("%d%d",&N,&M),N||M){
        vector<vector<edge> >V(N);
        for(int i=0;i<M;i++){
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            V[a].push_back(edge(b,c));
            V[b].push_back(edge(a,c));
        }
        priority_queue<edge,vector<edge>,greater<edge> >Q;
        Q.push(edge(0,0));
        bool used[100];fill(used,used+100,false);
        int res=0;
        while(Q.size()){
            int to=Q.top().to,cost=Q.top().cost;
            Q.pop();
            if(used[to])continue;
            used[to]=true;
            res+=cost;
            for(int i=0;i<V[to].size();i++)Q.push(V[to][i]);
        }
        printf("%d\n",res);
    }
}

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

int main(){
    int N;
    cin >> N;
    set<string> s;
    for (int i = 0; i < N; i++){
        string X;
        cin >> X;
        if (!s.count(X)) s.insert(X);
    }
    cout << s.size() << endl;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 5 * 1000 * 100 + 47;
string s;
vector<PII> A;
VI B;
int dp[MAX][4];

int calc(VI& A)
{
	FOR(i, 0, SZ(A) + 1)
	{
		FOR(t, 0, 4) dp[i][t] = -1;
	}

	dp[0][0] = 0;
	FOR(i, 0, SZ(A))
	{
		FOR(t, 0, 4)
		{
			if (dp[i][t] == -1) continue;

			if (t == 0)
			{
				dp[i + 1][2] = max(dp[i + 1][2], dp[i][0]);
				continue;
			}

			if (t == 1)
			{
				dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + A[i]);
				dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + A[i] - 1);
				dp[i + 1][2] = max(dp[i + 1][2], dp[i][1]);
				dp[i + 1][3] = max(dp[i + 1][3], dp[i][1] + 1);
				continue;
			}

			if (t == 2)
			{
				dp[i + 1][3] = max(dp[i + 1][3], dp[i][2] + A[i - 1]);
				dp[i + 1][2] = max(dp[i + 1][2], dp[i][2]);
				dp[i + 1][1] = max(dp[i + 1][1], dp[i][2] + A[i] - 1);
				dp[i + 1][0] = max(dp[i + 1][0], dp[i][2] + A[i]);
				continue;
			}

			dp[i + 1][3] = max(dp[i + 1][3], dp[i][3] + A[i - 1] - 1);
			dp[i + 1][2] = max(dp[i + 1][2], dp[i][3]);
			if (A[i - 1] > 1)
			{
				dp[i + 1][1] = max(dp[i + 1][1], dp[i][3] + A[i] - 1);
				dp[i + 1][0] = max(dp[i + 1][0], dp[i][3] + A[i]);
			}
		}
	}

	int ans = 0;
	FOR(t, 0, 4)
	{
		ans = max(ans, dp[SZ(A)][t]);
	}

	return ans;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n >> s;
	A.PB(MP(s[0] - '0', 1));
	FOR(i, 1, SZ(s))
	{
		if (s[i] == s[i - 1])
		{
			A.back().second++;
			continue;
		}

		A.PB(MP(s[i] - '0', 1));
	}

//	FOR(i, 0, SZ(A))
//	{
//		cout << A[i].first << " " << A[i].second << endl;
//	}

	int ans = 0;
	FOR(i, 0, SZ(A))
	{
		int bit = A[i].first;
		int cnt = A[i].second;

		if (bit == 0 && cnt > 1)
		{
			if (SZ(B)) ans += calc(B);
			B.clear();
			continue;
		}

		if (bit == 1)
		{
			B.PB(cnt);
		}
	}

	if (SZ(B)) ans += calc(B);

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


Measured memory_bytes: 3352
#include<bits/stdc++.h>
using namespace std;
#define int long long
int mian(){
	int n;
	cin>>n;
	string s;
	set<string>se;
	while(n--){
		cin>>s;
		se.insert(s);
	}
	cout<<se.size()<<endl;
	return 0;
}
signed main(){
	int t=1;
//	cin>>t;
	while(t--)
		mian();
	return 0;
}


Measured memory_bytes: 19248
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.StringTokenizer;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final int m = scanner.nextInt();

        final Map<Integer, List<Integer>> graph = new HashMap<>();
        for (int i = 0; i < m; i++) {
            final int a = scanner.nextInt();
            final int b = scanner.nextInt();
            graph.computeIfAbsent(a, v -> new ArrayList<>()).add(b);
            graph.computeIfAbsent(b, v -> new ArrayList<>()).add(a);
        }

        int begin = 1;
        int end = graph.get(1).get(0);
        final boolean[] isIncluded = new boolean[n + 1];
        final Deque<Integer> path = new ArrayDeque<>();
        final Consumer<Integer> init = endPoint -> {
            isIncluded[endPoint] = true;
            path.add(endPoint);
        };
        init.accept(begin);
        init.accept(end);

        extendPath(begin, path::addFirst, graph, isIncluded);
        extendPath(end, path::addLast, graph, isIncluded);

        System.out.println(path.size());
        final String answer = path.stream()
            .map(i -> Integer.toString(i))
            .collect(Collectors.joining(" "));
        System.out.println(answer);
    }

    private static void extendPath(final int endPoint, final Consumer<Integer> addPath, final Map<Integer, List<Integer>> graph, final boolean[] isIncluded) {
        final Optional<Integer> beginCandidate = graph.get(endPoint).stream()
            .filter(i -> !isIncluded[i])
            .findFirst();
        if (beginCandidate.isPresent()) {
            final int next = beginCandidate.get();
            isIncluded[next] = true;
            addPath.accept(next);
            extendPath(next, addPath, graph, isIncluded);
        }
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}


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


int main() {

    int a, b, c;
    cin >> a >> b >> c;
    if (a <= c && c <= b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto n :(array))

double eps = 1e-10 ;

  template <typename T>
void out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

template<typename T>
string ntos( T i ) {
  ostringstream s ;
  s << i ;
  return s.str() ;
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,ans = 0;
  while(1){
    cin >> n;
    if(n == 0){
      break ;
    }
    n = 1000-n;
    while(n >= 500){
      n -= 500;
      ++ans;
    }
    while(n >= 100){
      ++ans;
      n -= 100;
    }
    while(n >= 50){
      n -= 50;
      ++ans;
    }
    while(n >= 10){
      ++ans;
      n -= 10;
    }
    while(n >= 5){
      n -= 5;
      ++ans;
    }
    while(n >= 1){
      n -= 1;
      ++ans;
    }
    cout << ans<< endl;
    ans = 0;
  }
  return 0;
}

Measured memory_bytes: 1192
import sys

def DFS(index, tm, l, a, b):
 tm += 1
 a[index] = tm
 for i in l[index]:
  if not a[i-1]:
   tm = DFS(i-1, tm, l, a, b)
 tm += 1
 b[index] = tm
 return tm


n = input()
l=[]
for i in xrange(n):
 l.append([int(s) for s in sys.stdin.readline().split()[2:]])
a = [0] * n
b = [0] * n
tm = 0
for i in xrange(n):
 if not a[i]:
    tm = DFS(i, tm, l, a, b)

for i in xrange(n):
   print i+1, a[i], b[i]

Measured memory_bytes: 6504
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl;
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef queue<int> Q;
int GCD(ll a, ll b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

int main()
{
    int n;
    cin >> n;
    V a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    V left(n), right(n);
    left[0] = a[0];
    for (int i = 1; i < n; i++)
    {
        left[i] = GCD(left[i - 1], a[i]);
    }
    right[n-1] = a[n-1];
    for (int i = n - 2; i >= 0; i--)
    {
        right[i] = GCD(right[i+1], a[i]);
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (i == 0)
        {
            ans = max(ans, right[1]);
        }
        else if (i == n-1)
        {
            ans = max(ans, left[n-2]);
        }
        else
        {
            ans = max(ans, GCD(left[i-1], right[i+1]));
        }    
    }
    OUT(ans);
}
//wa

Measured memory_bytes: 1408
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC085COtoshidama solver = new ABC085COtoshidama();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC085COtoshidama {
        private static final ABC085COtoshidama.Pochibukuro[][] dp = new ABC085COtoshidama.Pochibukuro[2001][20001];
        private static final ABC085COtoshidama.Pochibukuro IMPOSSIBLE = new ABC085COtoshidama.Pochibukuro(-1, -1, -1);

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            ABC085COtoshidama.Pochibukuro p = calc(in.nextInt(), in.nextInt() / 1000);
            out.print(p.yukichi);
            out.print(' ');
            out.print(p.ichiyo);
            out.print(' ');
            out.println(p.soseki);
        }

        private static ABC085COtoshidama.Pochibukuro calc(int n, int y) {
            if (n == 0 && y == 0) {
                return new ABC085COtoshidama.Pochibukuro(0, 0, 0);
            } else if (n == 0 || y <= 0) {
                return IMPOSSIBLE;
            } else if (dp[n][y] != null) {
                return dp[n][y];
            }
            ABC085COtoshidama.Pochibukuro p;
            if ((p = calc(n - 1, y - 10)) != IMPOSSIBLE) {
                return dp[n][y] = new ABC085COtoshidama.Pochibukuro(p.yukichi + 1, p.ichiyo, p.soseki);
            } else if ((p = calc(n - 1, y - 5)) != IMPOSSIBLE) {
                return dp[n][y] = new ABC085COtoshidama.Pochibukuro(p.yukichi, p.ichiyo + 1, p.soseki);
            } else if ((p = calc(n - 1, y - 1)) != IMPOSSIBLE) {
                return dp[n][y] = new ABC085COtoshidama.Pochibukuro(p.yukichi, p.ichiyo, p.soseki + 1);
            } else {
                return dp[n][y] = IMPOSSIBLE;
            }
        }

        private static class Pochibukuro {
            private int yukichi;
            private int ichiyo;
            private int soseki;

            private Pochibukuro(int yukichi, int ichiyo, int soseki) {
                this.yukichi = yukichi;
                this.ichiyo = ichiyo;
                this.soseki = soseki;
            }

        }

    }
}


Measured memory_bytes: 230484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> b(n);
    vector<int> ans(n);
    rep(i,n) cin >> b[i];
    rep(ni, n){
        bool hasAns = false;
        for(int i = b.size() - 1; i >= 0; i--){
            if(b[i] == i + 1){
                b.erase(b.begin() + i);
                ans[n - ni - 1] = i + 1;
                hasAns = true;
                break;
            }
        }
        if(!hasAns){
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i,n){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>
int main(void) {
	char s[11];
	int i = 0;
	scanf("%s", s);
	if (s[i] == 'Y') {
		if (s[i+1]  == 'A') {
			if (s[i + 2] == 'K') {
				if (s[i + 3] == 'I') {
					printf("Yes\n");
				}
				else {
					printf("No\n");
				}
			}else printf("No\n");
		}else printf("No\n");
	}else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] nums = new int[N][31];
        int[] total = new int[31];
        for(int i=0; i<N; i++) {
            long num = sc.nextLong();
            int count = 0;
            while(num>1) {
                int remain = (int) (num % 2);
                nums[i][count] = remain;
                num -= remain;
                num/=2;
                if(total[count]==remain) {
                    total[count]=0;
                }else {
                    total[count]=1;
                }
                count++;
            }
            if(num==0) {
                nums[i][count]=0;
            }else {
                nums[i][count] = 1;
            }
            if(total[count]==nums[i][count]) {
                total[count]=0;
            }else {
                total[count]=1;
            }
        }

        for(int i=0; i<N; i++) {
            int answer = 0;
            for(int j=0; j<31; j++) {
                if(nums[i][j]!=total[j]) {
                    answer+=Math.pow(2, j);
                }
            }
            if(i==0) {
                System.out.print(answer);
            }else {
                System.out.print(" " + answer);
            }
        }
    }
}


Measured memory_bytes: 96908
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
signed main(){
    int n; cin>>n;
    vector<vector<int>>v(2,vector<int>(n,0));
    rep(i,2)rep(j,n)cin>>v[i][j];
    rep(i,2)rep(j,n){
        if(i==0&&j==0)continue;
        if(i==1&&j==0){
            v[i][j]+=v[i-1][j];
        }else if(i==0){
            v[i][j]+=v[i][j-1];
        }else v[i][j]+=max(v[i][j-1],v[i-1][j]);
    }
    cout<<v[1][n-1]<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Os") 
 
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define mp make_pair
 
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll maxn=5e2+10, lg=23, mod=1e9+7, inf=1e18;
 
ll h,w;
map<ll,bool> a[maxn],b[maxn];
 
 
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
 
	cin>>h>>w;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++){
		char c; cin>>c;
		if(c=='#') a[i][j]=b[i][j]=1;
		if(i==0)        a[i][j]=1;
		else if(i==h-1) b[i][j]=1;
		else if(j%2)    a[i][j]=1;
		else            b[i][j]=1;
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++) cout<<(a[i][j]?'#':'.');
		cout<<endl;
	}
	cout<<endl;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++) cout<<(b[i][j]?'#':'.');
		cout<<endl;
	}
 
	return 0;
}
 

Measured memory_bytes: 32000
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
#define int ll
#define double ld
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const int INF = 1LL<<60;
const double PI = acos(-1.0L);
const int dx[4] = {1, 0, -1, 0} , dy[4] = {0, 1, 0, -1};
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T> auto SUM(const T& a) { return accumulate(a.begin(),a.end(), 0); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; } return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
bool isSquare(ll n) {ll d = (ll)sqrt(n) - 1; while (d * d < n) ++d; return d * d == n;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);
    srand((unsigned)time(NULL));

    bool ok = 1;
    char a,b; cin >> a;
    REP(i,3){
        cin >> b;
        if(a==b) ok = 0;
        a = b;
    }
    if(ok) out("Good"); else out("Bad");

    return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc133/tasks/abc133_c

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

def main():
    l, r = map(int, input().split())

    l_i = l // 2019
    r_i = r // 2019
    if l_i != r_i:
        print(0)
    else:
        ans = l * r % 2019
        for x in range(l, r):
            for y in range(l + 1, r + 1):
                ans = min(ans, x * y % 2019)
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38896
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

int main(){
    ll n;
    cin >> n;
    ll a[n] ={},cnt[n] = {};
    rep(i,0,n-1){
        cin >> a[i];
        cnt[a[i]-1]++;
    }

    rep(i,0,n) cout << cnt[i] << endl;
    return 0;
}

Measured memory_bytes: 6692
//https://atcoder.jp/contests/abc119/tasks/abc119_c
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

int N, A, B, C;
vint l;

int ans = INF;

void calc(vint v){
	int tmp = -30;
	int a = 0, b = 0, c = 0;
	for (int i = 0; i < N; i++)
	{
		if(v[i]==0){
			a += l[i];
			tmp += 10;
		}else if(v[i]==1){
			b += l[i];
			tmp += 10;
		}else if(v[i]==2){
			c += l[i];
			tmp += 10;
		}
	}
	if(a==0||b==0||c==0){
		return;
	}

	tmp += abs(A - a) + abs(B - b) + abs(C - c);
	ans = min(ans, tmp);

	return;
}

void dfs(int depth,vint v){
	if(depth==N){
		calc(v);
		return;
	}
	for (int i = 0; i < 4; i++) {
		v[depth] = i;
		dfs(depth + 1, v);
	}
	return;
}

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

	cin >> N;
	cin >> A >> B >> C;
	l.resize(N);

	for(int i = 0; i < N; i++)
	{
		cin >> l[i];
	}

	vint v(N);
	dfs(0, v);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;


int main(void){
  int n;
  cin >> n;
  vector<int> L(n);
  rep(i,n) cin >> L[i];
  sort(L.begin(),L.end());

  //rep(i,n)cout << L[i] << " ";
  //cout << endl;
  ll ans = 0;
  for(int i=0;i<n;i++){
	for(int j=i+1;j<n;j++){
	  int len = L[i]+L[j];
	  auto iter = lower_bound(L.begin(),L.end(),len);
	  int index = iter - L.begin();
	  //cout << "L[i] = " << L[i] << ",L[j] =" << L[j] << ",L[k] = " << index << endl; 
	  ans += index-1-j;
	}
  }

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


Measured memory_bytes: 256