akhauriyash/Code-Regression huggingface dataset:
program main
  implicit none
  integer(8) :: n, m, s, i, rep
  integer(8), allocatable :: a(:), b(:), u(:), v(:), c(:), d(:), dp(:, :)
  read *, n, m, s
  allocate (a(m), b(m), u(m), v(m), c(n), d(n), dp(0:5000, n))
  do i = 1, m
    read *, u(i), v(i), a(i), b(i)
  end do
  do i = 1, n
    read *, c(i), d(i)
  end do
  dp = 10_8 ** 18
  dp(min(5000_8, s), 1) = 0
  call update_city(1_8)
  do rep = 1, n * 2
    do i = 1, m
      call move(i)
      call update_city(u(i))
      call update_city(v(i))
    end do
  end do
  do i = 2, n
    print "(i0)", dp(0, i)
  end do

  contains
  subroutine update_city(city)
    ! cityでの両替によりdp(:, city)を更新する
    integer(8), intent(in) :: city
    integer(8) :: i
    do i = 1, 5000  ! もらう
      if (i - c(city) >= 0) then
        dp(i, city) = min(dp(i, city), dp(i - c(city), city) + d(city))
      end if
    end do
    do i = 4999, 0, -1
      dp(i, city) = min(dp(i, city), dp(i + 1, city))
    end do
  end subroutine update_city

  subroutine move(edge)
    ! edge(city1-city2)の移動を評価することにより、dp(:, city[12])を更新する
    integer(8), intent(in) :: edge
    integer(8) :: from, to
    from = u(edge)
    to = v(edge)
    dp(0:5000 - a(edge), to) = min(dp(0:5000 - a(edge), to), dp(a(edge):5000, from) + b(edge))
    from = v(edge)
    to = u(edge)
    dp(0:5000 - a(edge), to) = min(dp(0:5000 - a(edge), to), dp(a(edge):5000, from) + b(edge))
  end subroutine move
end program main


Measured memory_bytes: 4924
def combination(n,r=-1):
    #res[r] = nPr
    if r==-1:
        r = n
    #nCrの一覧を返す。rの上限も 
    if (r<0) or (n<r):
        return 0
    cur = 1
    res = []
    res.append(cur)
    for i in range(1,r+1):
        cur *= n + 1 -i
        cur //= i
        res.append(cur)
    return res
N,P = [int(hoge) for hoge in input().split()]
A = sum([int(hoge)%2 for hoge in input().split()])
B = N - A#偶数
C = combination(A)
comb = 0
for i in range(P,A+1,2):
    comb += C[i]
print(2**B * comb)

Measured memory_bytes: 38384
import java.io.*;
import java.util.StringTokenizer;


public class Main {


    private void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int i = in.nextInt();
        int count = 0;
        for (int j = n; j >= 0; j--) {
            count++;
            if (j == i) {
                out.println(count);
                break;
            }

        }
    }

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

    private void run() {
        try (
                InputReader in = new InputReader(System.in);
                PrintWriter out = new PrintWriter(System.out)) {
            solve(in, out);
        }
    }


    static class InputReader implements AutoCloseable {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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


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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        @Override
        public void close() {

        }
    }

}


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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll sum = 0;
  if(d <= a){
    cout << d << endl;
    return 0;
  }
  else{
    sum += a;
    d = d -a;
  }
  if(d <= b){
    cout << sum << endl;
    return 0;
  }
  else{
    d  = d -b;
  }
  sum += (-1)*d;
  cout << sum << endl;
}

Measured memory_bytes: 3632
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int a, b, k;
  cin >> a >> b >> k;
  VI v;
  for(int i=a; i<a+k && i<=b; ++i) v.PB(i);
  for(int i=b; i>b-k && i>=a; --i) v.PB(i);
  sort(ALL(v));
  v.erase(unique(ALL(v)), v.end());

  for(int i: v) cout << i << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

int n,x,y,ans,dep[200100],fa[200100];
struct edge
{
    int v;
    edge *nxt;
} pool[800100],*tp=pool,*fst1[200100],*fst2[200100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

void dfs2(int x)
{
    dep[x]=dep[fa[x]]+1;
    for (edge *i=fst2[x]; i; i=i->nxt)
        if (i->v!=fa[x])
            fa[i->v]=x,dfs2(i->v);
}

bool check(int u,int v)
{
    for (int i=1; i<=2 && u!=v; u=fa[u],++i)
        if (dep[u]<dep[v])
            swap(u,v);
    return u!=v;
}

void dfs1(int x,int lst,int d)
{
    if (dep[x]<=d+1)
        return;
    ans=max(ans,(dep[x]-1)*2);
    for (edge *i=fst1[x]; i; i=i->nxt)
        if (i->v!=lst)
        {
            if (check(x,i->v))
            {
                puts("-1");
                exit(0);
            }
            dfs1(i->v,x,d+1);
        }
}

int main()
{
    scanf("%d%d%d",&n,&x,&y);
    repu(i,1,n-1)
    {
        int u=getint(),v=getint();
        *tp=(edge){v,fst1[u]},fst1[u]=tp++;
        *tp=(edge){u,fst1[v]},fst1[v]=tp++;
    }
    repu(i,1,n-1)
    {
        int u=getint(),v=getint();
        *tp=(edge){v,fst2[u]},fst2[u]=tp++;
        *tp=(edge){u,fst2[v]},fst2[v]=tp++;
    }
    dfs2(y),dfs1(x,0,0);
    printf("%d\n",ans);
    return 0;
}

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

using namespace std;
using ll = long long;
const int INF = 1e8;

//経路復元なしDijkstra法
template<class T> 
vector<T> dijkstra(int start, T INF, const vector<vector<pair<int,T>>>& Hen){
    int N = Hen.size();
    vector<T> dist(N, INF);
    vector<bool> seen(N);
    dist[start] = 0;
    priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> que;
    que.emplace(0, start);

    while(que.size()) {
        int ver = que.top().second;
        T cost = que.top().first; que.pop();
        if(seen[ver])continue;
        seen[ver] = true;
        for(auto i : Hen[ver]) {
            if(dist[i.first] > cost + i.second) {
                dist[i.first] = cost + i.second;
                que.emplace(dist[i.first], i.first);
            }
        }
    }
    return dist;
}


const vector<vector<int>> dir4 = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
int h, w;


int id(int y, int x) {return y * w + x;}

int main()
{
    cin >> h >> w;
    int ch, cw; cin >> ch >> cw; ch--, cw--;
    int dh, dw; cin >> dh >> dw; dh--, dw--;

    vector<vector<bool>> g(h, vector<bool>(w));
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            char c; cin >> c;
            g[i][j] = (c == '#');
        }
    }
    int n = h * w;
    
    vector<vector<pair<int,int>>> hen(h * w + 100);
    for(int i = 0; i < h; i++) {
        for(int j = 0; j< w; j++) {
            if(g[i][j])continue;
            for(auto d: dir4) {
                int ny = i + d[0], nx = j + d[1];
                if(ny < 0 || ny >= h || nx < 0 || nx >= w)continue;
                if(g[ny][nx])continue;
                hen[id(i, j)].push_back({id(ny,nx),0});
            }

            for(int ny = i - 2; ny <= i + 2; ny++) {
                for(int nx = j - 2; nx <= j + 2; nx++) {
                    if(ny == i && nx == j)continue;
                    if(ny < 0 || ny >= h || nx < 0 || nx >= w)continue;
                    if(g[ny][nx])continue;
                    hen[id(i,j)].push_back({id(ny,nx), 1});
                }
            }
        }
    }

    int num = dijkstra(id(ch, cw),INF, hen)[id(dh,dw)];
    cout << (num == INF ? -1 : num) << endl;


}

Measured memory_bytes: 112740
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

#define FOR(i,a,b) for(int i=(a);i<(b);++(i))
#define REP(i,n) FOR(i,0,n)

#define dump(x) cerr << #x << " = " <<(x)<<endl;
#define debug(x) cerr << #x << " = " <<(x) << "(L" << __LINE__ << ")" << __FILE__ << endl;

using namespace std;

int lis(string x, string y){
 vector<vector<int>> v(x.size()+1, vector<int>(y.size()+1));
  REP(i,(int)x.size()+1){
    REP(j,(int)y.size()+1){
      if(i==0 or j==0) v[i][j]=0;
      else if(x[i-1]==y[j-1]){ 
        v[i][j] = v[i-1][j-1]+1;
      }
      else{
        v[i][j]=max(v[i][j-1],v[i-1][j]);
      }
    }
  }
  return v[x.size()][y.size()];
}

int main(void){
  int i,j,q;
  cin >>q;
  string x;
  string y;
  REP(i,q) {
    cin >> x>> y;
    cout << lis(x,y)<< endl;

  }
  return 0;
}

Measured memory_bytes: 6840
#include<stdio.h>
int main(){
  int N,min = 1000000000,max = 0;
  scanf("%d",&N);
  int A[N];
  for(int i = 0;i < N;i++){
    scanf("%d",&A[i]);
    if(min > A[i]){
      min = A[i];
    }
    if(max < A[i]){
      max = A[i];
    }
  }
  printf("%d",max - min);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int n;
    ll l;
    cin >> n >> l;
    ll a[100010];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int check = -1;
    for(int i = 1; i < n; i++){
        if(a[i] + a[i + 1] >= l){
            check = i;
            break;
        }
    }
    if(check == -1){
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    for(int i = 1; i <= check - 1; i++){
        cout << i << endl;
    }
    for(int i = n - 1; i > check; i--){
        cout << i << endl;
    }
    cout << check << endl;

    return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    
    int i;
    for(i=1; i<=n; i++) {
        int x = i;
        if ( x % 3 == 0 ){
            printf(" %d", i);
            continue;
        }
        while( x ) {
            if ( x % 10 == 3 ){
              printf(" %d", i);
              break;
            }
            x /= 10;
         }
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2736
use text_io::*;
use std::collections::HashMap;
use std::process::exit;

fn main() {
    let mut a:usize = read!();
    let b:usize = read!();
    let c:usize = read!();
    let mut d:usize = c+b;
    let mut sum:usize = 0;
    if a>d {
        sum = (a/d)*b;
        a = a%d;
    }
    if a>b {
        sum += b;
    }
    else {
        sum+=a;
    }
    println!("{}",sum);
}

Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long N, X;
	cin >> N >> X;
	vector<long long>A(N);
	for (long long i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	A.push_back(X);
	sort(A.begin(), A.end());
	vector<long long>B(N);
	for (long long i = 0; i < N; i++) {
		B.at(i) = A.at(i + 1) - A.at(i);
	}
	for (long long i = 1; i < N; i++) {
		B.at(i) = __gcd(B.at(i - 1), B.at(i));
	}
	cout << B.at(N - 1) << endl;
}

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

using namespace std;

typedef long long ll;

void FASTIO() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
}

int main() {
	FASTIO();
	int n, m;
	cin >> n >> m;
	int ans1=0, ans2=0;
	for (int i=1; i<=n-1; i++) ans1+=i;
	for (int i=1; i<=m-1; i++) ans2+=i;
	cout << ans1 + ans2;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = [int(Ai) for Ai in input().split()]

counter = Counter(A)

dp = [1] * (max(A) + 1)
for Ai in A:
    for j in range(Ai * 2, len(dp), Ai):
        dp[j] = 0

print(sum([dp[Ai] == 1 and counter[Ai] == 1 for Ai in A]))


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


  
int main(){
    ll n;
    cin>>n;
    ll k;
    ll sum=0;
    vector<ll> a;
    rep(i,n){
        cin>>k;
        a.pb(k);
        sum+=k;
    }
    
    vector<ll> b(n,0);
    rep2(1,i,n){
        if(i%2==1)sum-=2*a[i];
    }

    b[0]=sum;

    rep2(1,i,n){
        b[i]=2*a[i-1]-b[i-1];
    }

    for(auto itr:b){
        cout<<itr<<" ";
    }cout<<endl;
    
    return 0;
}

Measured memory_bytes: 3060
import itertools

N = int(input())
# 1 <=    N <= 10^5
# 1 <= |Si| <= 10

count = [0, 0, 0, 0, 0]
char = ['M', 'A', 'R', 'C', 'H']
S = []
for n in range(N):
    s = input()
    S.append(s)
    for i, c in enumerate(char):
        if s[0] == c:
            count[i] += 1
        
# print(march)

# Choose three letters from MARCH.
# Number of combinations with the three letters are the multiplication of the sizes.
itr = itertools.combinations(range(5), 3)

total = 0
for cmb in itr:
    total += count[cmb[0]] * count[cmb[1]] * count[cmb[2]]

print(total)


Measured memory_bytes: 9876
import math


def li():
    return list(map(int, input().split()))


def mi():
    return map(int, input().split())


def ii():
    return int(input())


def is_prime(n):
    for i in range(2, int(math.sqrt(n))):
        if n % i == 0:
            return False
    return True


def next_prime(n):
    i = n
    while True:
        if is_prime(i):
            return i
        i += 1


X = ii()

print(next_prime(X))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

template<typename W>
// example const ll inf=1e15;
void dijkstra(int s, map<int,map<int,W>>& g, vector<W>& dist, const W inf) {
  vector<bool> visited(dist.size());
  fill(dist.begin(),dist.end(),inf);
  using P = pair<W,int>;
  priority_queue<P,vector<P>, greater<P>> pq;
  dist[s]=0;
  //visited[s]=true;
  pq.push(make_pair(0,s));
  while(!pq.empty()) {
    int v;
    W d;
    tie(d,v)=pq.top();
    pq.pop();
    if(visited[v]) continue;
    visited[v]=true;
    for(auto& uw : g[v]) {
      int u;
      W w;
      tie(u,w)=uw;
      if(visited[u]) continue;
      if(d+w<dist[u]) {
        dist[u]=d+w;
        pq.push(make_pair(dist[u],u));
      }
    }
  }
}


using G = map<int,map<int,int>>;
G make_kg(int n, vector<vector<int>> g) {
  G kg;
  repeat(v,1,n+1) {
    // move three times from s
    for(auto& u : g[v]) {
      kg[v][u+n]=1;
      kg[v+n][u+2*n]=1;
      kg[v+2*n][u]=1;
    }
  }

  return kg;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n,m;
  cin>>n>>m;
  vector<vector<int>> g(n+1);
  rep(i,m) {
    int u,v;
    cin>>u>>v;
    g[u].push_back(v);
  }
  int s,t;
  cin>>s>>t;
  G kg = make_kg(n,g);
  vector<int> dist(3*n+1);
  const int inf=1e8;
  dijkstra<int>(s,kg,dist,inf);
  if(dist[t]==inf) {
    cout << -1 << endl;
  } else {
    cout << dist[t]/3 << endl;
  }
  return 0;
}


Measured memory_bytes: 53376
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N,P;
		N =sc.nextInt();
		P =sc.nextInt();
		long oddCount=0,plusCount=0;
		long sum;
		for (int i=0;i<N;i++) {
			if (sc.nextInt()%2==0) {
				plusCount++;
			} else {
				oddCount++;
			}
		}
		if (P==1) {
			long plan =0;
			for (int i=1;i<=oddCount;i+=2) {
				plan +=C(i,oddCount);
			}
			sum =plan*nijyou(plusCount);
		} else {
			long plan =0;
			for (int i=0;i<=oddCount;i+=2) {
				plan +=C(i,oddCount);
			}
			sum =plan*nijyou(plusCount);
		}
		System.out.println(sum);
	}

	private static long nijyou(long n) {
		long result =1;
		for (int i=0;i<n;i++) {
			result =result *2;
		}
		return result;
	}
	private static long C(int m,long n) {
		long result =1;
		if (m>n/2) {
			m = (int)n-m;
		}
		for (int i=0;i<m;i++) {
			result= result *(n-i);
		}
		for (int i=1;i<=m;i++) {
			result = result/i;
		}
		if (result<0) {
			System.out.println("Error");
		}
		return result;
	}
}

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



int main(){
    int a,b;
    cin >> a >> b;
    int num1 = (a-b)/2;
    int num2 = (b+a)/2;
    if(abs(a-num1) == abs(b-num1)){
        cout << num1 << endl;
    }
    else if(abs(a-num2) == abs(b-num2)){
        cout << num2 << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }
    
    return 0;
    
}











Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b, c;
    cin >> a >> b >> c;
    int ans = max(0LL, c - (a - b));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) ((x).begin(), (x).end())
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

ll n, m;
V<V<int>> G;
V<V<ll>> x;
V<ll> dp;
V<int> pp;
V<ll> ans;

void dfs1(int i, int p) {
    dp[i] = 1;
    for(int e : G[i]) {
        if(e != p) {
            dfs1(e, i);
            x[i].push_back((dp[e] + 1) % m);
            dp[i] *= dp[e] + 1;
            dp[i] %= m;
        } else {
            pp[i] = x[i].size();
            x[i].push_back(-1);
        }
    }
}

void dfs2(int i, int p, ll d_p) {
    if(p != -1) {
        x[i][pp[i]] = d_p;
        ans[i] = dp[i] * d_p % m;
    }
    V<ll> s1, s2;
    s1 = s2 = x[i];
    rep(j, s1.size() - 1)(s1[j + 1] *= s1[j]) %= m;
    FORR(j, s2.size() - 1)(s2[j] *= s2[j + 1]) %= m;
    rep(j, G[i].size()) {
        if(G[i][j] == p) continue;
        ll d =
            ((j ? s1[j - 1] : 1) * (j + 1 < G[i].size() ? s2[j + 1] : 1) + 1) %
            m;
        dfs2(G[i][j], i, d);
    }
}

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

    cin >> n >> m;
    G.resize(n);
    dp.resize(n);
    x.resize(n);
    pp.assign(n, -1);
    ans.resize(n);
    rep(i, n - 1) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs1(0, -1);
    ans[0] = dp[0];
    dfs2(0, -1, 1);
    rep(i, n) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 26624
from collections import Counter
def solve():
    N = int(input())
    S = tuple(input() for _ in range(N))
    a = Counter(S).most_common()
    max = a[0][1]
    count = 0
    ans = set()
    for i,j in a:
        if j < max:
            break
        ans.add(i)
        count += 1
    ans = sorted(ans)
    print("\n".join(ans))
if __name__ == '__main__':
    solve()


Measured memory_bytes: 48008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1005;
int main(){
    double n,m,d;
    cin>>n>>m>>d;
    if(d==0)printf("%.9f",(m-1)/n);
    else printf("%.9f",(m-1)*2*(n-d)/n/n);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000, MAX_K = 100000;
int N, K;
string S;

int main() {

  cin >> N >> K;
  cin >> S;

  vector<char> v;
  v.push_back(S[0]);
  char c = S[0];
  for (int i = 1; i < N; ++i) {
    if (c != S[i]) {
      c = S[i];
      v.push_back(S[i]);
    }
  }

  int ans = 0;
  if (v[0] == v[len(v)-1]) {
    int totalFlip = (len(v)-1) / 2;
    if (K >= totalFlip) {
      ans = N - 1;
    } else {
      ans = N - 1 - (totalFlip-K) * 2;
    }
  } else {
    int totalFlip = len(v)/2;
    if (K >= totalFlip) {
      ans = N -1;
    } else {
      ans = N - 2 - (totalFlip-K-1)*2;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
#include<list>
#include<algorithm>
#define ld long double
#define pb push_back
#define FF first
#define SS second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repr(a,b,c) for(a=b-1;a>=c;a--)
#define PLL pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define PQ priority_queue
#define rep1 for(i=1;i<=n;i++)
#define VLL vector<ll>
#define EF else if
const double pi  =3.141592653589793238463;
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define UMP unordered_map
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define test4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define test5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define test6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
using namespace std;
/*
    //string with spaces
    std::string str;
    std::getline(std::cin >> std::ws, str);
*/
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);   
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    // fastio
    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r, t,u,w,x,y,z;
    string str, ss, str1;
    cin>>n;
    ll res = ceil((double)n/(double)1000);
    res *= 1000;
    ll out = res - n;
    cout<<out;
}

Measured memory_bytes: 3776
// AOJ 1340: Directional Resemblence
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int n, m, S, W, px[120009], py[120009], pz[120009], p[120009]; long double x[120009], y[120009], z[120009];
int main() {
	while(scanf("%d %d %d %d", &n, &m, &S, &W), n + m != 0) {
		for(int i = 0; i < n; ++i) {
			scanf("%d %d %d", &px[i], &py[i], &pz[i]);
		}
		for(int i = n; i < n + m; ++i) {
			px[i] = S / 7 % 100 + 1;
			py[i] = S / 700 % 100 + 1;
			pz[i] = S / 70000 % 100 + 1;
			if(S & 1) S = (S >> 1) ^ W;
			else S >>= 1;
		}
		n += m;
		for(int i = 0; i < n; ++i) {
			long double d = sqrt((long double)(px[i] * px[i] + py[i] * py[i] + pz[i] * pz[i]));
			x[i] = px[i] / d;
			y[i] = py[i] / d;
			z[i] = pz[i] / d;
			p[i] = i;
		}
		sort(p, p + n, [](int i, int j) {
			if(abs(x[i] - x[j]) > 1.0e-12L) return x[i] < x[j];
			if(abs(y[i] - y[j]) > 1.0e-12L) return y[i] < y[j];
			if(abs(z[i] - z[j]) > 1.0e-12L) return z[i] < z[j];
			if(px[i] != px[j]) return px[i] < px[j];
			if(py[i] != py[j]) return py[i] < py[j];
			return pz[i] < pz[j];
		});
		long double ans = 1.0e+9;
		int pa = -1, pb = -1, r = 0;
		for(int i = 0; i < n; ++i) {
			while(r != n && abs(x[p[i]] - x[p[r]]) < 1.0e-12L && abs(y[p[i]] - y[p[r]]) < 1.0e-12L && abs(z[p[i]] - z[p[r]]) < 1.0e-12) ++r;
			for(int j = r; j < n && (x[p[j]] - x[p[i]]) * (x[p[j]] - x[p[i]]) < ans - 1.0e-12L; ++j) {
				long double d = (x[p[i]] - x[p[j]]) * (x[p[i]] - x[p[j]]) + (y[p[i]] - y[p[j]]) * (y[p[i]] - y[p[j]]) + (z[p[i]] - z[p[j]]) * (z[p[i]] - z[p[j]]);
				if(d < ans - 1.0e-16L) {
					ans = d;
					pa = p[i];
					pb = p[j];
				}
			}
		}
		int ax = px[pa], ay = py[pa], az = pz[pa], bx = px[pb], by = py[pb], bz = pz[pb];
		if(ax > bx || (ax == bx && (ay > by || (ay == by && az > bz)))) {
			swap(ax, bx);
			swap(ay, by);
			swap(az, bz);
		}
		printf("%d %d %d %d %d %d\n", ax, ay, az, bx, by, bz);
	}
	return 0;
}


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

int main(){
	float pi=3.141592;
	float r;
	cin>>r;
	cout<<r*2*pi<<endl;

	return 0;

}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

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

    int t = 0;
    int i = 1;
    while(t < x){
        t += i;
        i++;
    }
    cout << i-1 << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).ToList();
        var ans = new int[n];
        ans[1] = Math.Abs(h[0] - h[1]);
        for (int i = 2; i < n; i++)
        {
            ans[i] = Math.Min(ans[i - 2] + Math.Abs(h[i] - h[i - 2]), ans[i - 1] + Math.Abs(h[i] - h[i - 1]));
        }
        Console.WriteLine(ans[n - 1]);
    }
}

Measured memory_bytes: 17376
#include<stdio.h>
#include<string.h>
int main(){
  int i,len=0,cnt=0;
  char s[100];
  scanf("%s",s);
  len=strlen(s);
  for(i=0; i<len/2; i++){
    if(s[i]!=s[len-i-1]){
      cnt++;
    }
  }
  printf("%d\n",cnt);
  return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    ll n, m, x, y;

    cin >> n >> m;

    vector<ll> sol(n, INT_MIN);

    vector<ll> endCnts(n, 0);
    vector<bool> processed(n, false);
    vector<vector<ll>> graph(n, vector<ll>());

    for (ll i=0; i<m; i++) {
        cin >> x >> y;
        graph[x-1].push_back(y-1);
        endCnts[y-1]++;
    }


    queue<ll> nodes;

    for (ll i=0; i<n; i++) {
        if (endCnts[i] == 0) {
            sol[i] = 0;
            nodes.push(i);
        }
    }

    ll current, nb;
    while (!nodes.empty()) {
        current = nodes.front();
        nodes.pop();
        for (ll i=0; i<graph[current].size(); i++) {
            nb = graph[current][i];
            sol[nb] = max(1+sol[current], sol[nb]);
            endCnts[nb]--;
            if (endCnts[nb] == 0 && !processed[nb]) {
                nodes.push(nb);
            }
        }

        processed[current] = true;
    }

    ll ans = INT_MIN;
    for (ll i=0; i<sol.size(); i++) {
        ans = max(ans, sol[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7296
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define reps(i, n) for(int i=1;i<=n;i++)
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rreps(i, n) for(int i=n;i>0;i--)
#define all(x) (x).begin(), (x).end()
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; }

ll N, M;

int main(){

    cin >> N >> M;
    if(N >= M){
        cout << 0 << endl;
        return 0;
    }
    vector<ll>X(M);
    rep(i, M)cin >> X[i];
    sort(X.begin(), X.end());
    vector<ll>Y;
    for(int i=1;i<X.size();i++)Y.push_back(X[i]-X[i-1]);
    sort(Y.begin(), Y.end());
    ll ans = 0;
    for(int i=0;i+N-1<Y.size();i++){
        ans += Y[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2168
/*************************
author : coldbeer
2019-05-26 05:24:41 PM IST
*************************/
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"

typedef long long ll;

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

	ll a,p; cin >> a >> p;
	ll tmp = 3 * a + p;
	ll ans = tmp / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n, m = (int(i) for i in input().split())

k_s = []
for i in range(m):
    k_s.append([int(x) for x in input().split()])
p = [int(x) for x in input().split()]
ans = 0
sw = [[0]*n for i in range(m)]

for i in range(m):
    for j in range(len(k_s[i])-1):
        sw[i][k_s[i][j+1]-1]=1
for i in range(2**n):
    s = [0]*n
    k=n-1
    while(i>=1):
        s[k] = (i%2)
        i = int(i/2)
        k -= 1
    tmp = [0]*m
    for j in range(m):
        f = 1
        for x in range(n):
            tmp[j] += sw[j][x]*s[x]
        if(tmp[j]%2!=p[j]):
            f = 0
            break
    ans += 1*f
print(ans)


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

int main(){
    ll n;
    scanf("%lld",&n);
    ll Ai[n];
    ll result[n];
    rep(i,n){
        result[i] = 0;
    }
    rep(i,n-1){
        scanf("%lld",&Ai[i]);
        result[Ai[i] - 1] = result[Ai[i] - 1] + 1;
    }
    rep(i,n){
        printf("%lld\n",result[i]);
    }
}

Measured memory_bytes: 6952
N = int(input())
MOD = 10 ** 9 + 7
M = 10 ** 5 + 1
rec = [0] * M
for i in range(1, N + 1):
    k = i
    for j in range(2, N + 1):
        while k >= 2 and k % j == 0:
            k //= j
            rec[j] += 1

num = 1
for k in list(filter(lambda x: x > 0, rec)):
    num *= k + 1
    num %= MOD

print(num)

Measured memory_bytes: 3828
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	vl x(n), y(m);
	REP(i, n)cin >> x[i];
	REP(i, m)cin >> y[i];
	ll xa = 0;
	REP(i, n - 1) {
		xa = (xa + (x[i + 1] - x[i])%MOD*(i+1)*(n-i-1)%MOD) % MOD;
	}
	ll res = 0;
	REP(i, m - 1) {
		res = (res + (xa*((y[i + 1] - y[i]) % MOD) % MOD)*(i + 1)*(m - i - 1) % MOD) % MOD;
	}
	cout << res << endl;
	return 0;
}


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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  int a, b; cin >> a >> b;
  if(a>b) swap(a, b);
  if(a==b or a+1==b){
    cout << "Yay!\n";
  } else {
    cout << ":(\n";
  }
  return 0;
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _176C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine() ?? string.Empty);
            var A = Console.ReadLine()?.Split(' ').Select(tmp => long.Parse(tmp)).ToArray();
            long fumidai = 0;

            long currentMaxHeight = A[0];
            long sum = 0;
            foreach (var ai in A)
            {
                if (ai >= currentMaxHeight)
                {
                    fumidai = 0;
                    currentMaxHeight = ai;
                }
                else
                {
                    fumidai = currentMaxHeight - ai;
                }

                sum = sum + fumidai;
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 47600
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K = ir()
    print(a[K-1])
resolve()

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<n;i++)
#define IREP(i,n) for(ll i=1;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define DEBUG(x) cerr << x << "\n"

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a;
    cin >> a;
    if(a == 1){
        cout << "Hello World\n";
    }
    else {
        int c,d;
        cin >> c >> d;
        cout << c + d << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (H, W) = listOfLong()
    var ans = Long.MAX_VALUE
    if (H * W % 3 == 0L) return println(0)
    fun solv(H: Long, W: Long) {
        for (h in 1 until H) {
            val d1 = h * W
            for (n in 0 .. 1) {
                val d2 =
                    if (n == 0) (H - h) / 2 * W // 三型
                    else (H - h) * (W / 2)      // Ｔ型
                val d3 = (H * W) - d1 - d2
                val d = listOf(d1, d2, d3).sorted()
                ans = Math.min(ans, d.last() - d.first())
            }
        }
    }
    solv(H, W)
    if (W != H) solv(W, H)
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }
fun listOfLong(offset: Long = 0L) = listOfString().map { it.toLong() + offset}


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

#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// type alias
using VI = std::vector<int>;
using VII = std::vector<VI>;
using VB = std::vector<bool>;
using VBB = std::vector<VB>;
using VS = std::vector<std::string>;
using PII = std::pair<int, int>;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  solve();
  return 0;
}

void solve() {
  int n, m;
  std::cin >> n >> m;
  cout((n-1) * (m-1));
}


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

n,q = map(int,input().split())

edges = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

counter = [0]*n
for i in range(q):
    p,x = map(int,input().split())
    counter[p-1] += x

def dfs(now,prev):
    for next in edges[now]:
        if next == prev:
            continue
        counter[next] += counter[now]
        dfs(next,now)

dfs(0,-1)
print(*counter)



Measured memory_bytes: 232720
H , W = map(int , input().split())
h_ans = 100000
w_ans = 100000

for h in range(1,H):
    Sa = h * W
    Sb = (H - h) * (W // 2)
    Sc = (H - h) * (W - ( W //2 ))
    if max(Sa,Sb,Sc) - min(Sa,Sb,Sc) < h_ans:
        h_ans = max(Sa,Sb,Sc) - min(Sa,Sb,Sc)
        
for h in range(1,H):
    Sa = h * W
    Sb = ((H - h)//2) * W
    Sc = (H - (h + (H-h)//2)) * W
    if max(Sa,Sb,Sc) - min(Sa,Sb,Sc) < h_ans:
        h_ans = max(Sa,Sb,Sc) - min(Sa,Sb,Sc)
    
for w in range(1,W):
    Sa = H * w
    Sb = (H // 2) * (W - w)
    Sc = (H - (H //2)) * (W - w)
    if max(Sa,Sb,Sc) - min(Sa,Sb,Sc) < w_ans:
        w_ans = max(Sa,Sb,Sc) - min(Sa,Sb,Sc)
    
for w in range(1,W):
    Sa = H * w
    Sb = H * ((W -w)//2)
    Sc = H * (W - (w + (W -w)//2) ) 
    if max(Sa,Sb,Sc) - min(Sa,Sb,Sc) < w_ans:
        w_ans = max(Sa,Sb,Sc) - min(Sa,Sb,Sc)
    
        
print((min(h_ans,w_ans)))

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

int main() {
    int N;
    string S;
    cin >> N >> S;

    int ans = 0;
    for (int i = 1; i < N; ++i) {
        bool used[2][26];
        fill(used[0], used[1] + 26, false);

        for (int j = 0; j < i; ++j) {
            used[0][S[j] - 'a'] = true;
        }
        for (int j = i; j < N; ++j) {
            used[1][S[j] - 'a'] = true;
        }

        int cnt = 0;
        for (int k = 0; k < 26; ++k) {
            cnt += (used[0][k] && used[1][k]);
        }

        ans = max(ans, cnt);
    }

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


Measured memory_bytes: 256
from bisect import bisect

a, b, q = map(int, input().split())
ss = [int(input()) for _ in range(a)]
tt = [int(input()) for _ in range(b)]
xx = [int(input()) for _ in range(q)]

def nearest2(ssortt, position) :
    l = len(ssortt)
    i = bisect(ssortt, position)
    if i == 0 : return (ssortt[0],)
    if i == l : return (ssortt[-1],)
    return (ssortt[i-1], ssortt[i])

for x in xx :
    ll = []
    for s in nearest2(ss, x) :
        for t in nearest2(tt, s) :
            ll.append(abs(s-x)+abs(t-s))
    for t in nearest2(tt, x) :
        for s in nearest2(ss, t) :
            ll.append(abs(t-x)+abs(s-t))
    print(min(ll))

Measured memory_bytes: 16144
void main() {
    int[] tmp = readln.split.to!(int[]);
    int a = tmp[0], b = tmp[1];
    writeln(max(a+b, a-b, a*b));
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.uni;

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

#define all(v) v.begin(), v.end()
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define REPE(i, x, n) for (int i = x; i <= n; i++)
#define OP(x) cout << x << endl;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
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) b = a; }
typedef long long ll;

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

    vector<int> t(s.size());
    t[0] = 0;
    for(int i = 1; i < s.size(); i++){
        t[i] = t[i - 1];
        if(s[i - 1] == 'A' && s[i] == 'C'){
            t[i]++;
        }
    }

    for(int i = 0; i < q; i++){
        int l, r; cin >> l >> r;
        int cnt = t[r - 1] - t[l - 1];
        if(cnt > 0) cout << cnt << endl;
        else cout << 0 << endl;
    }
}


Measured memory_bytes: 1408
using System;
using System.IO;
using System.Linq;

namespace AtCoder {
	class Program {
		public static void Main() {
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

			int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int n = input[0];
			int m = input[1];
			var a =  Console.ReadLine().Split(' ').Select(int.Parse);
			int test = a.OrderByDescending(x => x).ToArray()[m-1];
			int border = a.Sum();
			Console.WriteLine(test * 4 * m < border ? "No" : "Yes");

			Console.Out.Flush();
		}
	}
}

Measured memory_bytes: 13396
// code.begin();
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back 
#define what_is(x) cerr<<#x<<" is "<<x<<endl;
#define print(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define my_time ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long 
#define endl "\n"
#define MOD 1000000007
const long long int INF=1e18;
#define mod 1000000007
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    ordered_set; 
//find_by_order(x)
//order_of_key(x)  


int power(int x,unsigned int y)
{
    int res=1;
    
    while(y>0)
    {
        // if y is odd multiply with result
        if(y&1)
        res=res*x;
        
        y=y>>1; // y=y/2;
        x=x*x;
        
    }
    return res;
}

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

ll  max3(ll  a, ll  b, ll c)
{
    return max(c, max(a, b));
}
int min3(int a, int  b, int  c)
{
    return min(a, min(b, c));
}

int  powermod(int  x, int  y, int p )
{
    int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
int logg(int  a)
{
    int  x = 0;
    while (a > 1)
    {
        x++;
        a /= 2;
    }
    return x;
}


int modinv(int x)
{
    return powermod(x, mod - 2, mod);
}



int  main(){
	my_time;

int t;
t=1;
//cin>>t;int test=0;
while(t--)
{
   int n;
   int w;
   cin>>n>>w;
   int weight[n+1];
   int value[n+1];
   int sum=0;
   for(int i=1;i<=n;i++)
   {
       cin>>weight[i]>>value[i];
       sum+=value[i];
   }

   ll dp[n+1][sum+1];
   dp[0][0]=0;
   
   for(int i=1;i<=sum;i++)
   {
       dp[0][i]=1e18;
   }
   
   ll ans=0;
   for(int i=1;i<=n;i++)
   {
     for(int j=0;j<=sum;j++)
     {
        
         
         if(value[i]<=j)
         {
             dp[i][j]=min(dp[i-1][j],weight[i]+dp[i-1][j-value[i]]);
         }
         else
         dp[i][j]=dp[i-1][j];
         
         //cout<<dp[i][j]<<endl;
            
   if(dp[i][j]<=w)
   ans=max(ans,(ll)j);
     }
   }

 //  cout<<dp[n][sum]<<endl;
   cout<<ans<<endl;
   
   
}
    return 0;
}


//code.end();





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

vector<int>ans;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n1,n2,m1,m2,f=0;
    cin>>n1>>m1>>n2>>m2;
    int a[10] = {1,3,5,7,8,10,12};
    for(int i=0;i<7;i++){
        if(n1==a[i]) f=1;
    }
    if(f==1 && m1 ==31) cout<<1;
    else if(f==0 && n1 == 2 && m1==28) cout<<1;
    else if(f==0 && m1 == 30) cout<<1;
    else cout<<0;
    return 0;
}
 

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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    // set<int> s;
    // rep(i,n) s.insert(a[i]);
    // if(s.size()==n) cout << "YES" << endl;
    // else cout << "NO" << endl;
    sort(a.begin(),a.end());
    a.erase(unique(a.begin(),a.end()),a.end());//末尾のイテレータをuniqueは返す
    if(a.size()==n) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector


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

int N; cin >> N;
VI P(N); invec(P);

int cnt = 0;
i64 mini = P[0];
rep(i, 0, N){
    if (P[i] <= mini) ++cnt;
    mini = min(mini, P[i]);
}
cout << cnt << "\n";

}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 1792