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

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int h, w; cin >> h >> w;
	int cnt = 0;
	vector<vector<char> > s(h, vector<char>(w));
	REP(i, h) REP(j, w) {
		char c; cin >> c;
		if (c == '.') cnt++;
		s[i][j] = c;
	}

	vector<vector<int> > d(h, vector<int>(w, -1));
	d[0][0] = 0;

	queue<P> que;
	que.push(make_pair(0, 0));

	while (!que.empty()) {
		P pos = que.front();
		int y = pos.first;
		int x = pos.second;
		que.pop();

		REP(i, 4) {
			int next_y = y + dy[i];
			int next_x = x + dx[i];
			if (next_y < 0 || next_y >= h || next_x < 0 || next_x >= w)
				continue ;
			if (s[next_y][next_x] == '#')
				continue ;
			if (d[next_y][next_x] == -1) {
				que.push(make_pair(next_y, next_x));
				d[next_y][next_x] = d[y][x] + 1;
			}
		}
	}

	if (d[h - 1][w - 1] == -1) cout << -1 << '\n';
	else cout << cnt - d[h -1][w - 1] - 1 << '\n';
    return 0;
}


Measured memory_bytes: 3640
l,r=map(int,input().split())
if l//2019!=r//2019:
  print(0)
else:
  ans=10000000
  L,R=l%2019,r%2019
  for i in range(L,R):
    for j in range(i+1,R+1):
      c=(i*j)%2019
      if c<ans:
        ans=c
  print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;
class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

			Scanner sc=new Scanner(System.in);

			int a=sc.nextInt();
			int b=sc.nextInt();

			int num=a*b;

			if(num%2==0) {
				System.out.println("Even");
			}else {
				System.out.println("Odd");
			}

			sc.close();
	}

}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  int ans = 0;
  for( int i = 0; i < 2; i++ ){
    if( A > B ){
      ans += A;
      A--;
    }else{
      ans += B;
      B--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define ALL(v) v.begin(),v.end()
typedef long long ll;
int main() {
  int k,x;
  cin >> k >>x;
  for(int i=x-k+1; i<x+k; i++){
    cout << i << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

    ll x, y;
    cin >> x >> y;

    ll ans;
    if (x * y == 0) {
        ans = abs(y) + abs(x) + (y < 0) + (x > 0);
    } else if (x * y < 0) {
        ans = abs(abs(y) - abs(x)) + 1;
    } else {
        if (y > x) ans = y - x;
        else ans = x - y + 2;
    }

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
const int M = 1000000007;
const double PI = atan(1) * 4;
const int oo = 1000000000;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back 
#define all(c) (c).begin(),(c).end()


int main(){
	int a,b,c;
	cin>>a>>b>>c;
	c=a*100+b*10+c;
	if(c%4==0)cout<<"YES";
	else cout<<"NO";
	
}




Measured memory_bytes: 764
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			m = scanner.nextInt();
			n = scanner.nextInt();
			if ((m | n) == 0)
				break;
			M = new HashMap<Integer, Integer>();
			h = 1;
			a = new int[n][m];
			Y = new int[24];
			X = new int[24];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++) {
					int t = scanner.nextInt();
					if (t == 0) {
						a[i][j] = -1;
					} else if (t == 1) {
						Y[h] = i;
						X[h] = j;
						a[i][j] = h++;
					} else {
						Y[0] = i;
						X[0] = j;
						a[i][j] = 0;
					}
				}
			System.out.println(slove(0, 1));
		}
	}

	private int slove(int cur, int bit) {
		int k = cur << 24 | bit;
		if (M.containsKey(k))
			return M.get(k);
		int res = 0;
		for (int[] mo : move) {
			int y = Y[cur];
			int x = X[cur];
			while (true) {
				y += mo[0];
				x += mo[1];
				if (!isOK(y, x))
					break;
				if (a[y][x] == 0)
					if (Integer.bitCount(bit)==h){
						res++;
						break;
					}
				if (a[y][x] >= 1) {
					if ((bit >> a[y][x] & 1) == 1)
						continue;
					res += slove(a[y][x], bit | 1 << a[y][x]);
					break;
				}
			}
		}
		M.put(cur << 24 | bit, res);
		return res;
	}

	private boolean isOK(int y, int x) {
		if (0 <= y && y < n && 0 <= x && x < m)
			return true;
		return false;
	}

	int m, n, h;
	int[] Y, X;
	int[][] a;
	int[][] move = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };
	Map<Integer, Integer> M;
}

Measured memory_bytes: 186444
s = input()
k = int(input())
#l = "abcdefghijklmnopqrstuvwxyz"
#print(ord("b")) 97
ans = []
for i in range(len(s)):
    x = 0
    for j in range(5):
        if (i+j<len(s)):
            x += (ord(s[i+j])-96)*10**(8-2*j)
            ans.append((x,s[i:i+j+1]))
ans = list(set(ans))
ans.sort()
#print(ans)
print(ans[k-1][1])

Measured memory_bytes: 13680
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c, d float64
	fmt.Scan(&a, &b, &c, &d)
	var res float64
	if b-c <= 0 || d-a <= 0 {
		res = 0
	} else {
		// if a <= c && b >= d {
		// 	res = d - c
		// } else if a >= c && b <= d {
		// 	res = b - a
		// } else if a >= c && b >= d {
		// 	res = d - a
		// } else {
		// 	res = b - c
		// }
		min := math.Min(b, d)
		max := math.Max(a, c)
		res = min - max
	}
	fmt.Println(res)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#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 INF 2e9
#define MOD (long long int)(1e9+7)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
double logbase(double a, double base)
{
  return log(a) / log(base);
}
ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}
 
ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}

int main()
{
  
  ll n,k;cin>>n>>k;
  ll ans = 0;
  rep(m, min(k+1, n)){
    ll ret = 1;
    ret *= nCr(n, m);
    ret *= nCr(n-m-1 + m , n-m-1);
    ret %= MOD;
    ans += ret;
    ans %= MOD;
  }
    if(ans>=0){
      cout << ans << endl;
    }else{
      cout << ans+MOD << endl;
    }
}


Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define dbg(x) cout<<#x<<" = "<<x<<endl;
int main()
{
	map<ll,ll>a,b;
	//a中记录身高位置的加权值、有几个这样的身高；
	//b中记录身高位置的减权值、有几个这样的身高。 
	ll n,i,t;
	ll s=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&t);
		a[i+t]++;
		b[i-t]++;
	}
	map<ll,ll>::iterator it=a.begin();
	//如果a中的加权值在b中也有，那么他们就是一组，他们的数量之积就是要累加的量 
	for(;it!=a.end();it++)
	{
		s=s+(*it).second * b[(*it).first];
	}
	cout<<s;
	return 0;
}

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

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

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

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


int main(){
  int N, d[SIZE];

  cin >> N;

  ll ans = 0;
  for (int i=0; i<N; i++) {
    cin >> d[i];

    for (int j=0; j<i; j++) {
      ans += d[i] * d[j];
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  ll h,w;
  cin >> h >> w;
  
  if (h == 1 || w == 1) {
    cout << 1 << endl;
    return 0;
  }
  
  ll first = 0;
  ll second = 0;
  if (w % 2 == 0) {
    first = w / 2;
    second = first;
  } else {
    first = (w / 2) + 1;
    second = first - 1;
  }
  
  ll ans = 0;
  if (h % 2 == 0) {
    ans = (first + second) * (h / 2);
  } else {
    ans = (first + second) * (h / 2) + first;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
    out << '(' << p.first << ',' << p.second << ')';
        return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
    in >> p.first >> p.second;
        return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
    for (T &x : v)
                in >> x;
        return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
    for (const vector<T> &x : v)
                out << x << '\n';
        return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
    for (const T &x : v)
                out << x << ' ';
        return out;
}
 
template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
    for (const T &x : s)
            out << x << ' ';
        return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define epsilon 0.00000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl "\n"
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main()
{
    fast();
    ll x;
    cin>>x;
    cout<<(x==0)<<nl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

ll a[5000];
int dp1[5005][5000], dp2[5005][5000];//前から、逆から
int main() {
	ll n, k; scanf("%lld%lld", &n, &k);
	rep(i, n)scanf("%lld", &a[i]);
	dp1[0][0] = 1;
	rep(i, n) {
		for (int j = 0; j < k; j++) {
			dp1[i + 1][j] += dp1[i][j];
			if (j + a[i] < k)dp1[i + 1][j + a[i]] += dp1[i][j];
		}
	}
	dp2[n][0] = 1;
	dp2[n - 1][0] = 1;
	if (a[n - 1] < k)dp2[n - 1][a[n - 1]] = 1;
	for (int i = n - 1; i > 0; i--) {
		for (int j = 0; j < k; j++) {
			dp2[i - 1][j] += dp2[i][j];
			if (j + a[i - 1] < k)dp2[i - 1][j + a[i - 1]] += dp2[i][j];
		}
	}
	rep(i, n + 1) {
		for (int j = 1; j < k; j++) {
			dp2[i][j] += dp2[i][j - 1];
		}
	}
	int ans = 0;
	rep(i, n) {//使わない数
		bool flag = 0;
		if (a[i] >= k)continue;
		for (int j = 0; j < k; j++) {
			if (dp1[i][j] == 0)continue;
			if (j + a[i] >= k) {
				flag = 1; break;
			}
			//許容範囲
			int s = k - a[i] - j - 1, g = k - j - 1;
			int a = (s < 0 ? 0 : dp2[i + 1][s]);
			int b = (g < 0 ? 0 : dp2[i + 1][g]);
			if (b - a) {
				flag = 1; break;
			}
		}
		if (!flag)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 195712
package main

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

type action struct {
	b int
	c int
}

type actions []action

func (a actions) Len() int {
	return len(a)
}

func (a actions) Swap(i,j int) {
	a[i],a[j] = a[j],a[i]
}

func (a actions) Less(i,j int) bool {
	return a[i].c > a[j].c
}

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()
	m := scanInt()

	a := make([]int, n)
	for i:=0; i<n; i++ {
		a[i] = scanInt()
	}
	sort.Ints(a)

	//act := make([]action,m)
	act := make(actions,m)

	for i:=0; i<m; i++ {
		act[i].b, act[i].c = scanInt(), scanInt()
	}

	// sort.Slice(act, func(i,j int) bool {
		// return act[i].c > act[j].c
	// })
	sort.Sort(act)

	ans := 0

	for i:=0; i<n; i++ {
		ans += a[i]
	}

	p := 0
	b := act[p].b

	for i:=0; i<n; i++ {
		if act[p].c-a[i]<=0 {
			break
		}
		ans += act[p].c-a[i]
		b--
		if b == 0 {
			p++
			if p == m {
				break
			}
			b = act[p].b
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll s[110000];
bool ok;
ll ans;
ll m, n, k;
ll a, b;

bool solve(ll index) { //条件判定
	ll now = index, sum = index, t = 1;
	while (now > 0 and t < n) {
		sum += now / 2;
		now /= 2;
		t++;
	}
	if (sum <= k) return true;
	return false;
}

ll nibutan() { //めぐる式

	ll ng = k + 1; //最大値ならs.size()
	ll ok = 0; // 最大値なら0

	while (abs(ok - ng) > 1) {
		ll mid = (ok + ng) / 2;

		if (solve(mid)) ok = mid;
		else ng = mid;
	}
	return ok; //満たさない最大ならng
}
int main() {
	cin >> n >> k;
	cout << nibutan() <<endl;
}




Measured memory_bytes: 3112
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    s=input()
    ans=0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                if str(i) in s:
                    index_i=s.index(str(i))
                    s1=s[index_i+1:]
                    if str(j) in s1:
                        index_j=s1.index(str(j))
                        s2=s1[index_j+1:]
                        if str(k) in s2:
                            ans+=1
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 42608
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        int a = in.ni();
        char op = in.ns().toCharArray()[0];
        int b = in.ni();
        out.println((op=='+')?a+b:a-b);
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 22484
import bisect
from collections import deque

N = int(input())
A = [int(input()) for _ in range(N)]

dp = deque()
dp.append(A[0])

for i in range(1, N):
    ind = bisect.bisect_left(dp, A[i])

    if ind == 0:
        dp.appendleft(A[i])
    # elif dp[-1] < A[i]:
    #     dp[-1] = A[i]
    else:
        dp[ind-1] = A[i]

print(len(dp))

Measured memory_bytes: 13888
import sys
input=sys.stdin.readline
n=int(input())
h=tuple(map(int,input().split()))

dp=[0]
dp.append(abs(h[1]-h[0]))

for i in range(2,n):
    dp.append(min(dp[-2]+abs(h[i]-h[i-2]),dp[-1]+abs(h[i]-h[i-1])))

print(dp[-1])

Measured memory_bytes: 89904
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        boolean found = false;
        int ans = 0;
        int target = 1;
        for (int i = 0; i < n; i++) {
            if (a[i] == 1) {
                found = true;
            }
            if (a[i] == target) {
                target++;
            } else {
                ans++;
            }
        }

        if (!found) {
            ans = -1;
        }
        System.out.println(ans);

        sc.close();
    }

}


Measured memory_bytes: 89072
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}


int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

//#############################
const int MAXN = 1000005;
const int INF = 0x3f3f3f3f;
int n, k;
vector<ll> h;
ll memo[MAXN];

int main() {
    cin >> n >> k;
    ll x;
    for(int i = 0; i < n; i++)
        cin >> x, h.pb(x);
    memset(memo, INF, sizeof(memo));
    memo[0] = 0;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (j <= i)
                memo[i] = min(memo[i], memo[i-j] + abs(h[i]-h[i-j]));
        }
    }
    cout << memo[n-1];
    return 0;
}

Measured memory_bytes: 8948
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var foo = Console.ReadLine().Trim();
            var bar = Console.ReadLine().Trim();
            Console.WriteLine(foo == bar.Substring(0, foo.Length) ? "Yes" : "No");
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 17392
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a,b;
  cin >> a >> b;
  cout << b+(b-a) << endl;
}


Measured memory_bytes: 256
def solve(n, aaa):
    odd_idx, even_idx = [], []
    odd_sum, even_sum = 0, 0

    for i in range(0, n, 2):
        if aaa[i] > 0:
            even_idx.append(i)
            even_sum += aaa[i]
    for i in range(1, n, 2):
        if aaa[i] > 0:
            odd_idx.append(i)
            odd_sum += aaa[i]

    if odd_sum < even_sum:
        ans = even_sum
        idx = even_idx
    else:
        ans = odd_sum
        idx = odd_idx
    if ans == 0:
        import numpy as np
        i = np.argmax(aaa)
        ans = aaa[i]
        buf = list(range(n, i + 1, -1)) + [1] * i
        return ans, buf

    j = idx[-1]
    buf = list(range(n, j + 1, -1))
    for i in idx[-2::-1]:
        buf.extend(range((i + j) // 2 + 1, i + 1, -1))
        j = i
    buf += [1] * idx[0]
    return ans, buf


n = int(input())
aaa = list(map(int, input().split()))
ans, buf = solve(n, aaa)
print(ans)
print(len(buf))
print('\n'.join(map(str, buf)))


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n, m;
	cin >> n >> m;

	vector<int> h(n);
	vector<bool> isGood(n, true);

	for(int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}
	for(int i = 0; i < m; ++i)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;

		isGood[a] = isGood[a] & ( h[b] < h[a] );
		isGood[b] = isGood[b] & ( h[a] < h[b] );
	}

	int ans = 0;
	for(int i = 0; i < n; ++i)
	{
		if( isGood[i] )
		{
			ans++;
		}
	}

	cout << ans << endl;

}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3736
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<climits>
using namespace std;

int main() {
  long long ans=1;
  long long cnt=0;
  long long N =0;
  long long M =0;
  long long mns1=0;
  long long mns2=0;
  long long tmp = 0;
  long long now = 0;
  long long acnt=0;
  //i=0
  mns2=1;
  //i=1
  mns1=1;
  
  cin >> N >> M;

  if(N==1){
    cout << "1" << endl;
    return 0;
  }

  vector<long long> a(M), b(M+1);

  if(M > 0){
    for(long long i = 0; i < M; i++){
      cin >> a[i];

      if(i > 1 && (a[i-1] + 1) == a[i]){
        //    cout << "NOt exist a way to step up floor." << endl;
        cout << "0" << endl;
        return 0;
      }
    }

    if(a[acnt] == 1){
      mns1 = 0;
      acnt++;
    }

    for(long long i = 2; i <= N; i++){
      if(i==a[acnt]+1){
        now = mns2;

        mns2 = 0;
        mns1 = now;
      
        acnt++;
      }else if(i == a[acnt]){
        //cout << "This Floor is Broken!." << endl;
        now=0;
        mns2= mns1;
        mns1=0;
      }else{
        now = mns1 + mns2;

        mns2 = mns1;
        mns1 = now;
      }

      if(now > 1000000007){
        now = now%1000000007;
      }
      if(mns1 > 1000000007){
        mns1 = mns1%1000000007;
      }
      if(mns2 > 1000000007){
        mns2 = mns2%1000000007;
      }

      //cout << "*** i = " << i << endl;
      //cout << "mns1 = " << mns1 << ", mns2 = " << mns2 << endl;
      //cout << " now = " << now << endl;
    }
  }else{
    for(long long i = 2; i <= N; i++){
        now = mns1 + mns2;

        mns2 = mns1;
        mns1 = now;

        if(now > 1000000007){
          now = now%1000000007;
        }
        if(mns1 > 1000000007){
          mns1 = mns1%1000000007;
        }
        if(mns2 > 1000000007){
          mns2 = mns2%1000000007;
        }
    }
  }

    cout << now%1000000007 << endl;

}


Measured memory_bytes: 1792
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String ans;
		if (n <= 999) {
			ans = "ABC";
		}else {
			ans = "ABD";
		}
		System.out.println(ans);
	}

}


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

int main()
{
	int a,b;
	cin>>a>>b;
	if (a%3==0)
	{
		cout<<"Possible\n";
		return 0;
	}
	if (b%3==0)
	{
		cout<<"Possible\n";
		return 0;
	}
	if ((a+b)%3==0)
	{
		cout<<"Possible\n";
		return 0;
	}
	cout<<"Impossible\n";
	return 0;
}

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

using namespace std;

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



int main()
{
  int n, m;
  cin>>n>>m;
  int ai, bi;

  int countRoads[n+1] = {0};
  for(int i=0; i<m;i++)
  {
    cin>>ai>>bi;
    countRoads[ai]++;
    countRoads[bi]++;
  }

  for(int i=1; i<=n; i++)
  {
    cout<<countRoads[i]<<endl;
  }

  return 0;
}


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

namespace ABC137B
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] KX = CIN.IntArray();
            for (int i = KX[1] - KX[0] + 1; i < KX[1] + KX[0]; i++)
            {
                Console.Write(i + " ");
                
            }
            Console.WriteLine("");
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

Measured memory_bytes: 13268
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n * 3);
  for (int i = 0; i < n * 3; i++) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  long long ans = 0;
  for (int i = 1; i < 2 * n; i += 2) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
typedef long long int ll;
using namespace std;

int main(){
	int a,b,c; cin >>a>>b>>c;
	int ans=c/(7*a+b)*7+min(7,(c-c/(7*a+b)*(7*a+b)+(a-1))/a);
	cout << ans << endl;
}


Measured memory_bytes: 3096
# Shell sort
def insertion_sort(A,n,g):
    cnt = 0
    for i in range(g, n):
        v = A[i]
        j = i-g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j-g
            cnt += 1
        A[j+g] = v
    return cnt
def shell_sort(A,n):
    cnt = 0
    # an+1 = an + 3**(n-1)
    # n ????¶????????????????????????§G?????????
    idx = 1
    G = [1]
    while True:
        nxt = G[idx-1] + 3**idx
        if nxt > n:
            break
        idx += 1
        G.append(nxt)
    G.reverse()
    m = len(G)
    print(m)
    print(' '.join(list(map(str, G))))
    for i in range(m):
        cnt += insertion_sort(A,n,G[i])
    print(cnt)
    for i in range(n): print(A[i])
n = int(input())
A = [int(input()) for _ in range(n)]
shell_sort(A,n)


Measured memory_bytes: 47536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 *
 * @author Arles
 */
public class Main {

    static int[] jumps;
    static int oo = Integer.MAX_VALUE;
    static int[] memo;
    
    
    public static int dp(int i, int N) {
        if (i == N-1) {
            return 0;
        }

        if(memo[i] != -1){
            return memo[i];
        }
        
        int sA= oo, sB = oo;
        if (i + 1 < N) {

            sA = Math.min(oo, dp(i + 1, N) + Math.abs(jumps[i] - jumps[i + 1]));
            //System.out.println("A" + jumps[i] + ", " + jumps[i+1]  + ":" + sA);
        }
        if (i + 2 < N) {

            sB = Math.min(oo, dp(i + 2, N) + Math.abs(jumps[i] - jumps[i + 2]));
            //System.out.println("B" + jumps[i] + ", " + jumps[i+1]);
            
        }
        //System.out.println("escoge = "+ Math.min(sA, sB));
        return memo[i] = Math.min(sA, sB);
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        memo = new int[N];
        
        Arrays.fill(memo, -1);
        
        jumps = Arrays.stream(br.readLine().split(" ")).mapToInt((x) -> Integer.parseInt(x)).toArray();
        System.out.println(dp(0, N));

    }

}


Measured memory_bytes: 59428
#include <stdio.h>
#include <stdlib.h>
#define MAX 10001
int main() {
int i,j;
int n,m,a[MAX],b[MAX],key,count=0;
scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%d",&a[i]);
}
scanf("%d",&m);
for(i=0;i<m;i++){
    scanf("%d",&b[i]);
}
i=0;
for (j = 0; j < m; j++) {
  key=b[j];
  while (a[i]!=key) {
    i++;
    if(i==n) {break;}
  }
  if(i!=n) {count++;}
  i=0;
}
printf("%d\n",count);

return 0;
}



Measured memory_bytes: 2108
#aとbの差が奇数の時、一方は端で1試合留まってもう一方を迎えに行く。
n,a,b = gets.chomp.split(' ').map(&:to_i)
if a < b
  c = b#bを退避
  b = a#bをaに
  a = c#aをc = bに
end
if (a - b) % 2 == 0
  puts (a - b) / 2
else
  if b - 1 < n - a #より端に近い方に両方が向かう
    puts (a + b - 1) / 2
  else
    puts n - (a + b - 1) / 2
  end
end

Measured memory_bytes: 14416
while True:
    a=int(input())
    if a==0:
        break
    b=(1000-a)//500
    c=(1000-a)%500//100
    d=(1000-a)%500%100//50
    e=(1000-a)%500%100%50//10
    f=(1000-a)%500%100%50%10//5
    g=(1000-a)%500%100%50%10%5
    print(b+c+d+e+f+g)


Measured memory_bytes: 5584
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i = s; i < t ; ++i)
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define UNIQ(a) a.erase(unique(ALL(a)),a.end())
#define debug(a) cerr<<#a":="<<a<<endl;
#define SZ(a) (int)a.size()
using LL = long long; template<class T> using V = vector <T>; template <class T> using VV = V<V<T>>;

// 変数jを今すぐやめろ
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int N;
	while (cin >> N, N) {
		V<int>p(N), j(N);
		FOR(i, 0, N) {
			cin >> p[i];
		}
		
		FOR(i, 0, N - 1) {
			cin >> j[i];
		}
		sort(j.rbegin(), j.rend());
		LL sum = accumulate(ALL(p), 0LL);
		LL ans = sum*N;
		LL C = N;
		FOR(i, 0, N-1) {
			sum += j[i];
			C--;
			ans = max(ans, (C)*sum);
		}

		cout << ans << endl;

	}
}



Measured memory_bytes: 3364
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
        sc.Scan()
        i, e := strconv.Atoi(sc.Text())
        if e != nil {
                panic(e)
        }
        return i
}

func main() {
        sc.Split(bufio.ScanWords)
        n := nextInt()

        max := -1000000.0
        min := +1000000.0
        sum := 0

        for i := 0; i < n; i++ {
                x := nextInt()

                min = math.Min(float64(x), min)
                max = math.Max(float64(x), max)
                sum += x
        }
        fmt.Printf("%.0f %.0f %d\n", min, max, sum)
}


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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

int main(){
    ll n; cin >> n;
    vector<ll> alis(n+1), blis(n), clis(n+1);
    REP(i, 0, n+1){cin >> alis[i];}
    REP(i, 0, n){cin >> blis[i];}
    clis = alis;
    for(int i = n-1; i >= 0; i--){
        ll pre = alis[i+1];
        alis[i+1] = max(alis[i+1] - blis[i], 0LL);
        blis[i] -= (pre - alis[i+1]);
        pre = alis[i];
        alis[i] = max(alis[i] - blis[i], 0LL);
        blis[i] -= (pre - alis[i]);
    }
    ll ans = 0;
    REP(i, 0, n+1){
        ans += abs(clis[i] - alis[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <utility>
#include <string>
#include <vector>
#include <queue>
#include <set>
using namespace std;

int main(){
	int n,t,h,l,z=0;
	vector<int> vt(n+1), vh(n+1);
	cin>>n>>t>>h>>l;
	for(int i=1; i<=n; i++){
		cin>>vt[i]>>vh[i];
	}
	while(1) for(int i=1; i<=n; i++){
		if(vt[i]>0){
			z += 10;
			t++;
			vt[i]--;
		}else if(vh[i]>0){
			z += 100;
			h++;
			vh[i]--;
		}else{
			cout<<i<<endl;
			return 0;
		}
		if(t > l){
			cout<<i<<endl;
			return 0;
		}
		if(z >= 90){
			z -= 90;
			t -= z/10;
			vt[i] += z/10;
			z = 0;
			if(t < 0){
				cout<<i<<endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 35396
#include <stdio.h>

int main(void) {
	int X, Y, kame, turu, c = 1, T = 0;
	scanf("%d", &X);
	scanf("%d", &Y);
	for (kame = 0; kame <= 100; kame++) {
		for (turu = 0; turu <= 100; turu++) {
			if (kame + turu == X) {
				if (kame * 4 + turu * 2 == Y) {
					printf("Yes");
					T = 1;
				}
			}
		}
	}
	if (T == 0) {
		printf("No");
	}

	return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
long long XX(long long X)
{
	return (X*(X+1)/2ll)%1000000007ll;
}
int main()
{
	long long A,B;
    cin>>A>>B;
    long long Ans=0;
    for(long long i=B;i<=A+1;i++)
    {
    	Ans+=(XX(A)-XX(i-1)-XX(A-i)+2000000015ll)%1000000007ll;
        Ans%=1000000007ll;
    }
    cout<<Ans<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<chrono>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    int h, w, k; cin >> h >> w >> k;
    string s[h];
    arr<int> g(h, vector<int>(w, 0));
    rep(i, h) cin >> s[i];
    int ci = 1;
    rep(i, h) rep(j, w){
        if(s[i][j]=='#') g[i][j] = ci++;
    }

    rep(i, h) rep(j, w-1){
        if(g[i][j]==0) continue;
        if(g[i][j+1]==0) g[i][j+1] = g[i][j];
    }
    // prarr(g);

    for(int i=h-1; i>=0; i--) for(int j=w-1; j>0; j--){
        if(g[i][j]==0) continue;
        if(g[i][j-1]==0) g[i][j-1] = g[i][j];
    }
        
    FOR(i, 1, h) rep(j, w){
        if(g[i][j]!=0) continue;
        g[i][j] = g[i-1][j];
    }

    for(int i=h-2; i>=0; i--) for(int j=w-1; j>=0; j--){
        if(g[i][j]!=0) continue;
        g[i][j] = g[i+1][j];
    }

    prarr(g);
    return 0;}

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

int main(){
	long x, y;
	cin >> x >> y;

	if(x > y){
		x %= y;
	}else if(x < y){
		y %= x;
	}

	if(x > y){
		x %= y;
	}else if(x < y){
		y %= x;
	}

	long start = min(x, y);

	for(long i = start; i > 0; i--){
		if( x % i == 0 && y % i == 0 ){
			cout << i << endl;
			break;
		}
	}
	return 0;
}


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b > c+d)cout << "Left" << endl;
    else if(a+b == c+d)cout << "Balanced" << endl;
    else cout << "Right" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

using namespace std;

ll k;
ll n=50;

ll f(ll i) {
    if (k%n==0) return k/n;
    if (i>=k%n) return k/n;
    return k/n+1;
}

int main() {
    scanf("%lld",&k);
    printf("%lld\n",n);
    for (ll i=0;i<n;i++) {
        printf("%lld ",(n+1)*f(i)-k+i);
    }
    printf("\n");
}

Measured memory_bytes: 256
program ABC158_D
  character(100000)::S
  character(1)::Fs(200000),Bs(200000),Ss(300000)
  integer::Q,T,F,rev,Fi,Bi
  character(5)::query
  character(1)::C
  read(5,*)S
  read(5,*)Q
  N=len_trim(S)
  rev=0
  Fi=0
  Bi=0
  do I=1,Q
     read(5,'(A)')query
     if(query(1:1)=='1') then
        rev=rev+1
     else
        read(query,*)T,F,C
        if((F==1 .and. mod(rev,2)==0) .or. (F/=1 .and. mod(rev,2)==1)) then
           Fi=Fi+1
           Fs(Fi)=C
        else
           Bi=Bi+1
           Bs(Bi)=C
        end if
     end if
  end do
  do I=1,len_trim(S)
     Ss(I)=S(I:I)
  end do
  if(mod(rev,2)==1) then
     write(6,*)Bs(Bi:1:-1),Ss(len_trim(S):1:-1),Fs(1:Fi)
  else
     write(6,*)Fs(Fi:1:-1),Ss(1:len_trim(S)),Bs(1:Bi)
  end if
end program ABC158_D

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B;
    cin >> A >> B;
    cout << A * B << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
typedef long long ll;
ll MOD=(ll)1e9+7;
//i个球分成j组的方案数
ll dp[1005][1005];//dp[i][j]:i个球分成j组的方案数
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    dp[0][0]=1;
    rep(i,1,n)rep(j,1,i){
        dp[i][j]+=dp[i-1][j]*j%MOD;//加入别的组
        dp[i][j]+=dp[i-1][j-1];//自己一组
        dp[i][j]%=MOD;
    }
    cout<<dp[n][k]<<endl;

}
/* 

 */


Measured memory_bytes: 10008
c = [[0 for i in range(3)] for j in range(3)]
for i in range(3):
	c[i] = list(map(int,input().split()))

res = False

for b0 in range(0,100):
	a0 = c[0][0] - b0
	a1 = c[1][0] - b0
	a2 = c[2][0] - b0

	b1 = set()
	b2 = set()
	b1.add(c[0][1] - a0)
	b1.add(c[1][1] - a1)
	b1.add(c[2][1] - a2)
	b2.add(c[0][2] - a0)
	b2.add(c[1][2] - a1)
	b2.add(c[2][2] - a2)
	if (len(b1) == 1 and len(b2) == 1):
		res = True
		break

print("Yes" if res == True else "No") 

Measured memory_bytes: 3064
n=int(input())
a=list(map(int,input().split()))
#n=6
#a=[3, 1, 2, 4, 2, 1]

a.sort(reverse=True)
#print(a)

i=0
icnt=0
ai=0
while icnt<=1 and i<=n-2:
    icnt=1
#    print("3",i,a[i],a[i+1])
    while i<=n-2 and a[i]==a[i+1]:
        ai=a[i]
        i+=1
        icnt+=1 
#    print("1",i,icnt,ai)
    i+=1

#print("4",i,icnt,ai)
if icnt>=4:
    print(ai*ai)
elif icnt>=2:
    icnt=0
#    print("5",i)
    while icnt<=1 and i<=n-2:
        icnt=1
#        print("3",i,a[i],a[i+1])
        while i<=n-2 and a[i]==a[i+1] :
            ai2=a[i]
            i+=1
            icnt+=1
#        print("2",i,icnt,ai2)
        i+=1
    if icnt>=2:
        print(ai*ai2)
    else:
        print(0)
else:
    print(0)

Measured memory_bytes: 14480
#from functools import reduce
from collections import deque

#解説見た

def solve(N, K, A):
    MOD = int(1e9 + 7)
    A_plus = [x for x in A if x >= 0]
    A_plus.sort(reverse=True)
    A_minus = [x for x in A if x < 0]
    A_minus.sort()

    if K == 1:
        return max(A) % MOD
    if K == N:
        #ans = reduce(operator.mul, A)
        ans = 1
        for t in A:
            ans *= t
            ans %= MOD
        return ans % MOD

    if len(A_plus) == 0:
        #minusだけから選ぶ場合
        if K % 2 == 1:
            #答えは負になるので、絶対値が小さい順に積を取る
            ans = 1
            for t in list(reversed(A_minus))[:K]:
                ans *= t
                ans %= MOD
            return ans
        else:
            #答えは正になるので、絶対値が大きい順に積をとる
            ans = 1
            for t in A_minus[:K]:
                ans *= t
                ans %= MOD
            return ans
    
    k = K
    S = []
    A_plus = deque(A_plus)
    A_minus = deque(A_minus)
    if k % 2 == 1:
        t = A_plus.popleft()
        S.append(t)
        k -= 1
    #kは偶数になった
    assert k % 2 == 0
    while k > 0:
        if len(A_minus) < 2:
            t1 = A_plus.popleft()
            S.append(t1)
            t2 = A_plus.popleft()
            S.append(t2)
            k -= 2
        elif len(A_plus) < 2:
            t1 = A_minus.popleft()
            S.append(t1)
            t2 = A_minus.popleft()
            S.append(t2)
            k -= 2
        else:
            t_p = A_plus[0] * A_plus[1]
            t_m = A_minus[0] * A_minus[1]
            if t_p >= t_m:
                t1 = A_plus.popleft()
                S.append(t1)
                t2 = A_plus.popleft()
                S.append(t2)
                assert t1 * t2 == t_p
                k -= 2
            else:
                t1 = A_minus.popleft()
                S.append(t1)
                t2 = A_minus.popleft()
                S.append(t2)
                assert t1 * t2 == t_m
                k -= 2
    ans = 1
    for t in S:
        ans *= t
        ans %= MOD
    return ans % MOD

if __name__ == "__main__":
    #with open('ABC173E/random_mz03.txt', 'r') as f:
    #    input = f.readline
    N, K = tuple(int(c) for c in input().split())
    A = [int(c) for c in input().split()]
    ret = solve(N, K, A)
    print(ret)

Measured memory_bytes: 107928
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		long mod = 1000000007;
		long H = GetLong();
		long W = GetLong();
		long A = GetLong();
		long B = GetLong();

		ModCombTable mct = new ModCombTable((int)(H + W), mod);
		long ans = 0;
		for(long i = B+1; i <= W; i++)
		{
			long comb = (mct.ModComb(H-A+i-2, i-1) * mct.ModComb(W-i+A-1, A-1)) % mod;
			ans = (ans + comb) % mod;
		}

		Console.WriteLine(ans);
	}
}


public class ModCombTable
{
	private long[] f = null;
	private long[] fInv = null;
	private long mod;

	public ModCombTable(int N, long m)
	{
		mod = m;

		// calc factorial
		f = new long[N+1];
		f[0] = 1;
		for(int i = 1; i <= N; i++)
			f[i] = (f[i-1] * i) % mod;

		// calc factorial inverse
		fInv = new long[N+1];
		fInv[N] = ModInv(f[N]);
		for(int i = N; i > 0; i--)
			fInv[i-1] = (fInv[i] * i) % mod;
	}

	public long ModComb(long n, long k)
	{
		return (((f[n] * fInv[k]) % mod) * fInv[n-k]) % mod;
	}

	public long ModInv(long x)
	{
		return ModPow(x, mod - 2);
	}

	public long ModPow(long x, long n)
	{
		long res = 1;
		while(n > 0)
		{
			if((n & 1) == 1)
				res = (res * x) % mod;
			x = (x * x) % mod;
			n >>= 1;
		}
		return res;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 14048