akhauriyash/Code-Regression huggingface dataset:
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

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

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

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    int64 n, a, b;
    cin >> n >> a >> b;
    print(n / (a + b) * a + min(n % (a + b), a));

    return 0;
}



Measured memory_bytes: 256
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-26 20:40:08
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int flag = 0;
  for (auto e : vec) os << (flag++ ? ", " : "{") << e;
  return os << (vec.empty() ? "{}" : "}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int flag = 0;
  for (auto e : st) os << (flag++ ? ", " : "{") << e;
  return os << (st.empty() ? "{}" : "}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int flag = 0;
  for (auto e : mp) os << (flag++ ? ", " : "{") << e;
  return os << (mp.empty() ? "{}" : "}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

// Calculate x^n (modulo mod)

template<class T, class U> T mod_pow(T x, U n, T mod) {
  T res = 1;
  while (n > 0) {
    if (n & 1) (res *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return res;
}

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

  string s; cin >> s;
  int n = s.size();

  vector<int> dp(n);

  reverse(all(s));

  debug(s);

  int cur = 0;

  for (int i = 0; i < n; ++i) {
    cur += (s[i] - '0') * mod_pow(10, i, 2019);
    cur %= 2019;
    //debug(cur);
    dp[i] = cur;
  }

  //debug(dp);

  map<int, int> mp;

  int ans = 0;

  for (int e : dp) {
    if (e == 0) ++ans;
    ans += mp[e];
    ++mp[e];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4344
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  sm=l[0]
  for x in l[1:]:
    sm^=x

  ans=[]
  for x in l:
    sm^=x
    ans.append(sm)
    sm^=x

  return ' '.join(str(x) for x in ans)


# main()
print(main())


Measured memory_bytes: 43272
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	private static final int WHITE = 1;
	private static final int BLACK = 0;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int w = scanner.nextInt();
			int h = scanner.nextInt();
			int[][] cells = new int[w][h];
			IntStream.range(0, w).forEach(i -> Arrays.fill(cells[i], WHITE));
			int n = scanner.nextInt();
			IntStream.range(0, n).forEach(i -> {
				int x = scanner.nextInt() - 1;
				int y = scanner.nextInt() - 1;
				int a = scanner.nextInt();
				switch (a) {
				case 1:
					IntStream.rangeClosed(0, x).forEach(j -> Arrays.fill(cells[j], BLACK));
					break;
				case 2:
					IntStream.range(x + 1, w).forEach(j -> Arrays.fill(cells[j], BLACK));
					break;
				case 3:
					IntStream.rangeClosed(0, y).forEach(j -> IntStream.range(0, w).forEach(k -> cells[k][j] = BLACK));
					break;
				case 4:
				default:
					IntStream.range(y + 1, h).forEach(j -> IntStream.range(0, w).forEach(k -> cells[k][j] = BLACK));
					break;
				}
			});
			System.out.println(IntStream.range(0, w).map(i -> Arrays.stream(cells[i]).sum()).sum());
		}
	}
}


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


int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int count=0; 
    int i=0;
    int j=i+k-1;
   /* for(;i<=j;i++){
        mini= min(a[i],mini);
    }*/
    count++;
    while(j<n){
        if(j==n-1){
            break;
        }
        j=j+k-1;
        count++;
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
int mod=(int)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct

int main(void){
    int n=in(),i,j,t,ans=0;
    int f[CHAR_MAX]={};
    char s[101];
    chin(s);
    rep(i,n){
        MEMSET(f);
        t=0;
        if(i>0||i<n-1){
            rep(j,i){
                f[s[j]]=1;
            }
            for(;j<strlen(s);j++){
                if(f[s[j]])f[s[j]]++;
            }
        }
        for(j='a';j<='z';j++){
            if(f[j]>1)t++;
        }
        ans=max(ans,t);
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 128
import qualified Data.ByteString.Char8 as BC
import qualified Data.IntMap as M
import Data.Maybe (fromJust)
import Data.List
import Data.Array.IO
import Control.Monad

type Arr = IOUArray Int Int

main = do
  [h,w,d] <- map read . words <$> getLine :: IO [Int]
  a <- concat <$> replicateM h getIntListBC :: IO [Int]
  let m = foldl' register M.empty $ zip a [(i, j) | i <- [1..h], j <- [1..w]]
  arr <- newArray (1, h*w) 0 :: IO Arr
  foldM (solve m d) arr [d+1..h*w]
  q <- readLn :: IO Int
  replicateM q (query arr)
  return ()

register :: M.IntMap (Int, Int) -> (Int, (Int, Int)) -> M.IntMap (Int, Int)
register m (k, v) = M.insert k v m

solve :: M.IntMap (Int, Int) -> Int -> Arr -> Int -> IO Arr
solve m d arr i = do
  pre <- readArray arr $ i - d
  let (x, y) = fromJust $ M.lookup i m
      (s, t) = fromJust $ M.lookup (i-d) m
  writeArray arr i $ pre + (abs $ s - x) + (abs $ t - y)
  return arr

query :: Arr -> IO ()
query arr = do
  [l, r] <- map read . words <$> getLine :: IO [Int]
  ll <- readArray arr l
  rr <- readArray arr r
  print $ rr - ll

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getIntBC :: IO Int
getIntBC = bsToInt <$> BC.getLine

getIntListBC :: IO [Int]
getIntListBC = map bsToInt . BC.words <$> BC.getLine


Measured memory_bytes: 23804
#include <iostream>
using namespace std;
int main() {
    long long n, p; cin >> n >> p;
    if (n == 1) { cout << p << endl; return 0; }
    long long ans = 1;
    for (long long i = 2; i * i <= p; i++) {
        long long q = 1;
        for (int e = 0; e < n && q <= p; e++) q *= i;
        while (p % q == 0) { ans *= i; p /= q; }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  string s;
  cin >> n >> s;

  char a='1';
  ll c=0;

  for(ll i=0;i<n;i++){
    if(s[i]!=a){
      a=s[i];
      c++;
    }
  }
  cout << c <<endl;


}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b, h;
  cin >> a >> b >> h;
  cout << (a + b) * h / 2 << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

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

	int x = 0, y = 0;
	std::string str;
	std::cin >> x >> y;

	int tmp = y;
	do  {
		x *= 10;
	} while (tmp = tmp / 10);
	int z = x + y;
	int s = static_cast<int>(sqrt(z));
	if (z == s * s) {
		std::cout << "Yes";
	}
	else {
		std::cout << "No";
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void) {

int N;
unsigned long int a[1000000];
unsigned long int sum;
int i;

sum = 0;

scanf("%d", &N);

for (i = 0; i < N; i++) {

    a[i] = i + 1;
    //printf("a[%d]=%d\n", i, a[i]);

    if(a[i] % 3 == 0 || a[i] % 5 == 0) sum = sum;
    else sum += a[i];

    //printf("sum = %d\n", sum);
}

printf("%ld\n", sum);

return 0;

}

Measured memory_bytes: 1736
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  string s;
  while(cin>>s){
    int co[2]={0};
    rep(i,s.size()-2){
      if(s.substr(i,3)=="JOI")co[0]++;
      else if(s.substr(i,3)=="IOI")co[1]++;
    }
    cout<<co[0]<<endl<<co[1]<<endl;
  }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
using namespace std;
map <int,int> mp;
typedef pair<int, int> P;
typedef long long ll;
static const int MAX=100000;
static const int NMAX=50;
static const int MMAX=50;
int a,b,ans;

void solve(){
    ans =1;
    for(int i=0;i<a;i++) ans*=100;
    if(b!=100)ans*=b;
    else ans *= 101;
    cout<<ans <<"\n";
}

int main(){
    cin >> a >> b;
    solve();
    return 0;
}


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

int main() {
  // 入力を受け取る
  int N;
  cin >> N;

  // 計算
  
  // 両面印刷できないページはあるka 
  bool po = (N % 2) == 1;
  int  pageNum = (N / 2);
  
  if (po) {
    pageNum++;
  }
  
  // 出力
  cout << pageNum << endl;
}

Measured memory_bytes: 3520
/*
    アリナ・グレイが好きです。
*/

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

int main(void){
    int n;
    cin >> n;
    long long int sum = 0;
    for(int i = 0;i < n;i++){
        if((i+1)%3 != 0 && (i+1)%5 != 0)sum += (i+1);
    }
    cout << sum << endl;
}


Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
#input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#import numpy as np

from collections import deque

def main():
	s=input().rstrip()
	ans="Yes"
	n=len(s)
	for i in range(n):
		if s[i]!=s[-i-1]:
			ans="No"
	for i in range(n//2):
		if s[i]!=s[n//2-i-1]:
			ans="No"
	print(ans)





if __name__ == "__main__":
	main()

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

struct Edge {
	int to;
	int64_t dist{1};

	// int64_t cost;
	// int from;
	// int rev_i;
};
using EdgeVec = std::vector<Edge>;
using EdgeLists = std::vector<EdgeVec>;

template <typename Metric = int64_t>
class BellmanFord {
private:
	const EdgeLists& edges_;
	const int source_;
	std::vector<Metric> distance_;
public:
	const Metric inf, negative_inf;

	BellmanFord(const EdgeLists& edges, const int source)
		: edges_(edges), source_(source), distance_(edges.size(), std::numeric_limits<Metric>::max()),
		inf(std::numeric_limits<Metric>::max()), negative_inf(std::numeric_limits<Metric>::min())
	{
		distance_[source] = 0;
		for (int loop{}; loop < (int)edges_.size(); loop++)
			for (int now{}; now < (int)edges_.size(); now++)
				if (distance_[now] != inf)
					for (const Edge& next: edges_[now])
						distance_[next.to] = std::min(distance_[next.to], distance_[now] + next.dist);
		
		std::vector<bool> isInCycle(edges_.size());
		std::queue<int> updatedQueue;
		for (int from{}; from < (int)edges_.size(); from++)
			if (distance_[from] != inf)
				for (const Edge& next: edges_[from])
					if (!isInCycle[next.to] && distance_[from] + next.dist < distance_[next.to])
					{
						isInCycle[next.to] = true;
						updatedQueue.push(next.to);
					}
		while (!updatedQueue.empty())
		{
			int now{updatedQueue.front()};
			updatedQueue.pop();
			distance_[now] = negative_inf;
			for (const Edge& next: edges_[now])
				if (!isInCycle[next.to])
				{
					isInCycle[next.to] = true;
					updatedQueue.push(next.to);
				}
		}
	}

	// get distance_
	Metric operator[](const int index) const
	{
		return distance_[index];
	}

	decltype(distance_.begin()) begin() { return distance_.begin(); }
	decltype(distance_.end()) end() { return distance_.end(); }

	bool negativeCycleExists() const
	{
		for (const Metric& dist: distance_)
			if (dist == negative_inf)
				return true;
		return false;
	}
};

int main()
{
	int N, M, P;
	scanf("%d%d%d", &N, &M, &P);
	EdgeLists edges(N);
	for (int i{}; i < M; i++)
	{
		int A, B, C;
		scanf("%d%d%d", &A, &B, &C);
		A--; B--;
		edges[A].push_back({B, P - C});
	}
	BellmanFord<> bellmanFord(edges, 0);
	if (bellmanFord[N - 1] == bellmanFord.negative_inf)
		puts("-1");
	else
		printf("%lld\n", std::max(-bellmanFord[N - 1], 0l));
	return 0;
}

Measured memory_bytes: 512
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int n,ma,mb;
    cin>>n>>ma>>mb;
    int v[n+1][401][401];
    rep(i,0,n+1)rep(j,0,401)rep(k,0,401)v[i][j][k]=INF;
    v[0][0][0]=0;
    rep(i,0,n){
        int a,b,c;cin>>a>>b>>c;
        rep(j,0,400){
            rep(k,0,400){
                if(j-a>=0&& k-b>=0)v[i+1][j][k]=min(v[i][j][k],v[i][j-a][k-b]+c);
                else v[i+1][j][k]=v[i][j][k];
            }
        }
    }
    int ans=INF;
    rep(i,0,401)rep(j,0,401){
        if(j*ma==i*mb && i+j!=0)ans=min(ans,v[n][i][j]);
    }
    if(ans==INF)cout<<-1<<endl;
    else cout<<ans<<endl;

}

/*

*/


Measured memory_bytes: 25984
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0; i<N; i+=1)
using namespace std;

int main() {
  int N;
  cin>>N;
  vector<int>A(N);
  rep(i,N) cin>>A[i];
  vector<int>B(N);
  rep(i,N) cin>>B[i];
  vector<int>C(N-1);
  rep(i,N-1) cin>>C[i];
  int count=0;
  rep(i,N) count+=B[A[i]-1];
  rep(i,N) if(A[i]+1==A[i+1]) {
    count+=C[A[i]-1];
  }
  cout<<count<<endl;
}

  
  



Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from functools import reduce
from math import gcd
def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    if reduce(gcd, A) != 1:
        print("not coprime")
        return

    M = max(A)
    sieve = list(range(M + 1))
    primes = []

    for i in range(2, M + 1):
        if sieve[i] == i:
            primes.append(i)
        j = 0
        for p in primes:
            if not (p <= sieve[i] and i * p <= M):
                break
            sieve[i * p] = p

    used = set()
    for a in A:
        primes = set()
        while a > 1:
            p = sieve[a]
            primes.add(p)
            a //= p
        for p in primes:
            if p in used:
                print("setwise coprime")
                return
            used.add(p)

    print("pairwise coprime")
resolve()

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 1LL << 60;
    if (n % k == 0) {
        ans = 0;
    } 
    else if (n > k) {
        ll tmp = n / k;
        ans = min(ans, abs(n - (k * tmp)));
        ans = min(ans, abs(n - (k * tmp) - k));
    }
    else if (k > n) {
        if (n * 2 > k) ans = abs(n - k); 
        else ans = n;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll =long long;
using db = double;

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

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める
int main()
{
	cout << setprecision(10);
	int k , s ;
	cin >> k >> s;
	//x + y + z == s;  それぞれは kより小さい
	ll ans = 0;
	rep(i,k+1){
		int S = s;
		S-= i;
		rep(j,k+1){
			int K=S ;
			K-= j;
			if(K<=k && K>=0){
				ans ++;
			}
		}
	}
	cout << ans << endl;
		
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
#from numpy import sign
#import numpy as np
out = float('Inf')
for i in range(0, n - k + 1):
    ans = abs(a[i] - a[i + k - 1]) + min(abs(a[i]), abs(a[i + k - 1]))
    out = min(out, ans)
print(out)

Measured memory_bytes: 14224
#include<atcoder/all>
using namespace atcoder;

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int main() {
    int n, m;
    cin >> n >> m;
    vector<string> s(n);
    rep(i, n)cin >> s[i];
    mf_graph<int> g(n*m+2);
    int a = n*m, b = n*m+1;
    rep(i, n)rep(j, m){
        int now = i*m + j;
     	if(s[i][j] == '#')continue;
        if((i+j) & 1)g.add_edge(now, b, 1);
        else {
          	g.add_edge(a, now, 1);
          	rep(k, 4){
            	int ni = i + dx[k], nj = j + dy[k];
            	if(ni < 0 || ni >= n || nj < 0 || nj >= m)continue;
              	if(s[ni][nj] == '#')continue;
            	int next = m * ni + nj;
            	g.add_edge(now, next, 1);
        	}
        }
    }
    cout << g.flow(a, b) << endl;
  	auto es = g.edges();
  	rep(i, es.size()){
      	auto e = es[i];
      	if(!e.flow)continue;
      	if(e.from == a || e.to == b)continue;
      	if(e.to/m == e.from/m){
          	s[e.to/m][e.to%m] = '>';
          	s[e.from/m][e.from%m] = '<';
          	if(e.to%m > e.from%m)swap(s[e.to/m][e.to%m], s[e.from/m][e.from%m]);
        }else{
          	s[e.to/m][e.to%m] = 'v';
          	s[e.from/m][e.from%m] = '^';
          	if(e.to/m > e.from/m)swap(s[e.to/m][e.to%m], s[e.from/m][e.from%m]);         
        }
    }
  	rep(i, n)cout << s[i] << endl;
}


Measured memory_bytes: 5536
# include <iostream>
using namespace std;
int N, K;

int main() {
  cin >> N >> K;
  int ans = 0;
  for (int i = 0; i < N; i++) {
  	int h; cin >> h;
    if (h >= K) ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())
from fractions import gcd
g = gcd(A,B)

#素因数分解して列挙する関数、約数列挙ではない！
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    fct = list(set(fct))
    return fct

f = factorize(g)
ans = len(f)+1
print(ans)

Measured memory_bytes: 64620
N=int(raw_input())
A=raw_input()
ans=0
for i in range(N):
	B=raw_input()+"@"*1000
	a=A[0:2]
	
	L=[[-1],[-1]]
	for i in range(2):
		Ba=B
		while(1):
			ai=Ba.find(a[i])
			if ai==-1: break
			L[i].append(L[i][-1]+ai+1)
			Ba=Ba[ai+1:]
		L[i].pop(0)
	flg=0
	for p in L[0]:
		for q in L[1]:
			if q>p:
				r=q-p
				for j in range(2,len(A)):
					if B[q+r*(j-1)]!=A[j]:
						break
				else:
					ans+=1
					flg=1
					break
		if flg:
			break
print ans

Measured memory_bytes: 6392
# import itertools
# import math


def solve(W, H, x, y):
    area = W * H
    half_line_count = 0
    if (W / 2) == x and (H / 2) == y:
        half_line_count = 1
    return [area / 2, half_line_count]


# N = int(input())
# S = input()
W, H, x, y = map(int, input().split())
# A = list(map(int, input().split()))

# P = []
# S = []
# for i in range(N):
#     pp, ss  = map(int, input().split())
#     P.append(pp)
#     S.append(ss)

print(*solve(W, H, x, y))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll h;
    cin >> h;
    ll ans = 1;
    while(h > 0){
        h /= 2;
        ans *= 2;

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Runnable {

	static long mod = (long) (1e9 + 7L);

	public long Pow(long x, long y) {

		if (y == 0L)
			return 1L;

		if (y == 1L)
			return x;

		long pow = y;
		long ans = 1L;

		while (pow > 0) {

			if ((pow & 1) == 1)
				ans = (ans * x) % mod;

			pow /= 2;
			x = (x * x) % mod;
		}
		return ans % mod;
	}

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

		new Thread(null, new Main(), "SwapnilGanguly", 1 << 26).start();
	}

	public void run() {

		MyScanner sc = new MyScanner();
		PrintWriter pr = new PrintWriter(System.out);

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long ans = 0L;

		if ((a >= 0 && b >= 0) && (c >= 0 && d >= 0))
			ans = b * d;

		else if ((a >= 0 && b >= 0) && (c <= 0 && d <= 0))
			ans = a * d;

		else if ((a <= 0 && b <= 0) && (c >= 0 && d >= 0))
			ans = b * c;

		else if ((a <= 0 && b <= 0) && (c <= 0 && d <= 0))
			ans = a * c;
		else
			ans = Math.max(a * c, b * d);

		pr.println(ans);
		pr.close();
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 32980
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
//const int MOD = 1000000007;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main(){
  string s;
  cin>>s;
  int cnt=0;
  while(!s.empty()){
    if(s[0]==s[s.size()-1]){
      s.erase(s.size()-1,1);
      s.erase(0,1);
    }else if(s[0]!='x'&&s[s.size()-1]=='x'){
      cnt++;
      s.erase(s.size()-1,1);
    }else if(s[0]=='x'&&s[s.size()-1]!='x'){
      cnt++;
      s.erase(0,1);
    }else{
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<cnt<<endl;
  return 0;
  }

Measured memory_bytes: 3648
import fractions

n,x=map(int,input().split())
X=list(map(int,input().split()))
A=[]
for i in range(n):
    if X[i]!=x:
        A.append(abs(X[i]-x))
g=A[0]
for i in range(n):
    g=fractions.gcd(g,A[i])
print(g)

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

int main(){
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    bool water[31] = {};
    bool sugar[3001] = {};

    water[0] = sugar[0] = true;
    for(int i = 0; i < 31; i++){
        if(water[i] && i+a < 31)    water[i+a] = true;
        if(water[i] && i+b < 31)    water[i+b] = true;
    }
    for(int i = 0; i < 3001; i++){
        if(sugar[i] && i+c < 3001)  sugar[i+c] = true;
        if(sugar[i] && i+d < 3001)  sugar[i+d] = true;        
    }

    double maxRate = -1;
    int answater = 0, anssugar = 0;

    for(int i = 1; i <= f/100; i++){
        if(water[i]){
            int tmpsugar = i*e;
            for(;tmpsugar >= 0;tmpsugar--){
                if(sugar[tmpsugar] && tmpsugar+i*100 <= f) break;
            }
            
            if(tmpsugar == -1)  continue;

            if(100.0*tmpsugar/(i*100.0 + tmpsugar) > maxRate){
                maxRate = 100.0*tmpsugar/(i*100.0 + tmpsugar);
                answater = i*100;
                anssugar = tmpsugar;
            }
        }
    }

    cout << answater+anssugar << " " << anssugar << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, a, b, c;

  std::cin >> N;

  long long dp[2][3], *curr = dp[0], *next = dp[1];

  memset(dp, 0, sizeof(dp));

  for (int i = 0; i < N; i ++) {
    std::cin >> a >> b >> c;

    if (i == 0) {
      next[0] = a;
      next[1] = b;
      next[2] = c;
    }
    else {
      next[0] = std::max(curr[1] + a, curr[2] + a);
      next[1] = std::max(curr[0] + b, curr[2] + b);
      next[2] = std::max(curr[0] + c, curr[1] + c);
    }

    std::swap(curr, next);
  }

  std::cout << std::max(std::max(curr[0], curr[1]), curr[2]) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int i,o,t,j,l,s,z;
    int ans = 0;
    cin >> i >> o >> t >> j >> l >> s >>z;
    chmax(ans, int(i - i % 2) + o + int(j - j % 2) + int(l - l % 2) );
    if(i >= 1  and j>=1  and l >= 1){
    i --;
    j --;
    l --;
    chmax(ans, int(i - i % 2) + o + int(j - j % 2) + int(l - l % 2)  + 3);
    }
    if(i >= 1  and j>=1  and l >= 1){
    i --;
    j --;
    l --;
    chmax(ans, int(i - i % 2) + o + int(j - j % 2) + int(l - l % 2)  + 6);
    }
    cout << ans << endl;


}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int ma[100000]={};
int main(){
	string s;
	cin >> s;
	int n = s.size();
	
	int rindex,lindex;
	int r=0,l=0;
	REP(i,n){
		if(s[i] == 'R'){
			r++;
			if(i!=0 && s[i-1] == 'L'){
				ma[rindex] += l/2;
				ma[lindex] += l/2 + l%2;
				l = 0;
			}
		}else{
			l++;
			if(s[i-1] == 'R'){
				ma[i-1] += r/2 + r%2;
				ma[i] += r/2;
				rindex = i-1;
				lindex = i;
				r = 0;
			}
		}
	}
	if(l != 0){
		ma[rindex] += l/2;
		ma[lindex] += l/2 + l%2;
	}
	
		
	REP(i,n){
		cout << ma[i] << " ";
 	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
using namespace std;
using ll = long long;
int main(){
  vector<ll> miti(5);
  for(int i=0;i<3;++i){
    ll a,b;
    cin>>a>>b;
    miti[a]++;
    miti[b]++;
  }
  ll _1=0,_2=0;
  for(int i=1;i<=4;++i){
    if(miti[i]==1){
      _1++;
    }else if(miti[i]==2){
      _2++;
    }else{
      cout<<"NO"<<endl;
      return 0;
    }
  }
  if(_1==2&&_2==2){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}

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

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;


void solve()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int cur = 1;
	while (a > 0 and c > 0)
	{
		if (cur == 1)
		{
			c -= b;
			if (c <= 0) break;
			cur = 2;

		}
		else
		{
			a -= d;
			if (a <= 0) break;
			cur = 1;
		}

	}
	if (a > 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return;

}

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



	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
	char a, b;
	int c, d;
	cin >> a >> b;
	if (a == 'A') { c = 10; }
	if (a == 'B') { c = 11; }
	if (a == 'C') { c = 12; }
	if (a == 'D') { c = 13; }
	if (a == 'E') { c = 14; }
	if (a == 'F') { c = 15; }
	if (b == 'A') { d = 10; }
	if (b == 'B') { d = 11; }
	if (b == 'C') { d = 12; }
	if (b == 'D') { d = 13; }
	if (b == 'E') { d = 14; }
	if (b == 'F') { d = 15; }

	if (c < d) { printf("<\n"); }
	else if (c > d) { printf(">\n"); }
	else { printf("=\n"); }

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int a, b; cin >> a >> b;
  cout << max({a + b, a - b, a * b}) << '\n';
  return 0;
}


Measured memory_bytes: 256
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)


def combination(n, r, mod=10**9+7):
    """
    nCr mod m
    """
    if n < r:
        return 0
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


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

mod = 10**9 + 7
for i in range(1, k+1):
    print(combination(n-k+1, i) * combination(k-1, i-1) % mod)


Measured memory_bytes: 45276
#include <stdio.h>
#include<math.h>
int main(void){
   double a,b,c,s,l,h;
   scanf("%lf%lf%lf",&a,&b,&c);
   c*=3.14159265358979;
   c/=180;
   s=a*b*sin(c)/2;
   l=sqrt(a*a+b*b-2*a*b*cos(c))+a+b;
   h=2*s/a;
   printf("%lf\n%lf\n%lf\n",s,l,h);
    return 0;
}

Measured memory_bytes: 2920
import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.Map as M
import Text.Printf

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
  [h, w] <- readInts
  when ((h, w) /= (0, 0)) $ do
    putStrLn $ replicate w '#'
    forM_ [2..h-1] $ \_ -> do
      putChar '#'
      putStr $ replicate (w-2) '.'
      putChar '#'
      putChar '\n'
    putStrLn $ replicate w '#'
    putChar '\n'
    main



Measured memory_bytes: 4084
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,a) for(int i=lst[a];i;i=nxt[i])
using namespace std;

const int N=2e3+5;

int t[N<<1],nxt[N<<1],lst[N],l;
void add(int x,int y) {t[++l]=y;nxt[l]=lst[x];lst[x]=l;}

int n,x,y,low[N],dis[N],sz[N];
char s[N];

void dfs(int x,int y) {
	sz[x]=(s[x]=='1');low[x]=dis[x]=0;
	rep(i,x) 
		if (t[i]!=y) {
			dfs(t[i],x);
			sz[x]+=sz[t[i]];
			low[t[i]]+=sz[t[i]];
			dis[t[i]]+=sz[t[i]];
			dis[x]+=dis[t[i]];
		}
	int son=0;
	rep(i,x) if (t[i]!=y&&low[t[i]]>=low[son]) son=t[i];
	int sum=0;
	rep(i,x) if (t[i]!=y&&t[i]!=son) sum+=min(low[son],dis[t[i]]);
	low[x]=max(low[son]-sum,dis[x]&1);
}

int main() {
	scanf("%d",&n);
	scanf("%s",s+1);
	fo(i,1,n-1) {
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	int ans=1e9;
	fo(i,1,n) {
		dfs(i,0);
		if (!low[i]) ans=min(ans,dis[i]>>1);
	}
	printf("%d\n",(ans==1e9)?-1:ans);
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = input()
    Q = int(input())
    x = tuple(map(int,input().split()))
    for k in x:
        d,m,dm,dmc = 0,0,0,0
        for i in range(N):
            if S[i] == "D":
                d += 1
            elif S[i] == "M":
                m += 1
                dm += d
            elif S[i] == "C":
                dmc += dm
            if i >= k-1:
                if S[i-k+1] == "D":
                    dm -= m
                    d -= 1
                elif S[i-k+1] == "M":
                    m -= 1
        print(dmc)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 59884
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll n;
string s;

void input(){
    cin >> n >> s;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    map<char, ll> cnt;
    for(int i=0;i<s.size();i++){
        cnt[s[i]]++;
    }
    ll ans = 1;
    for(auto p:cnt){
        ans = (p.second + 1) * ans % MOD;
    }
    cout << ans-1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <string>
#include<queue>
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<map>
#include<tuple>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> t3;
typedef tuple<int,int,int,int> t4;

const int MX = 200005;
const int MM = 1000000007;

vector<int> G[MX], R[MX];
string D;
int nxt[26];
int dist[MX], d2[MX];
pii tr[MX];

int main()
{
	cin >> D;
	int N = D.size();
	for(int i = 0; i < 26; i++) nxt[i] = N+1;
	for(int i = N; i >= 0; i--){
		for(int j = 0; j < 26; j++){
			G[i].push_back(nxt[j]);
			R[nxt[j]].push_back(i);
		}
		if( i ) nxt[D[i-1]-'a'] = i;
	}
	queue<int> Q;
	Q.push(0); dist[0] = 1;
	while(Q.size()){
		int p = Q.front(); Q.pop();
		for(int c : G[p]){
			if(dist[c]) continue;
			dist[c] = dist[p] + 1;
			Q.push(c);
		}
	}

	Q.push(N+1); d2[N+1] = 1;
	while(Q.size()){
		int p = Q.front(); Q.pop();
		for(int c : R[p]){
			if(d2[c]) continue;
			d2[c] = d2[p] + 1;
			Q.push(c);
		}
	}
	int st = 0;
	string ans = "";
	while(st != N+1){
		for(int i = 0; i < 26; i++){
			int c = G[st][i];
			if( dist[c] + d2[c] == dist[N+1] + 1 && dist[c] == dist[st] + 1){
				ans.push_back(i + 'a'); st = c;
				break;
			}
		}
	}
	cout << ans << "\n";;
}


Measured memory_bytes: 71940
import java.util.Scanner;


public class Main {
    static int a;
    static String s;
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        a = stdIn.nextInt();
        s = stdIn.next();
        System.out.print(check());
    }
    private static String check(){
        if(a>=3200) return s;
        return "red";
    }
}

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

int main(){
    int N, P, m=1000000;
    int ans = 0;
    cin >> N;
    for (int i=0; i<N; i++){
        cin >> P;
        m = min(m, P);
        if (P <= m) ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int dx[]={-1,0,1,0},dy[]={0,-1,0,1};

struct xy{int x=0,y=0;};

int main(){

  for(;;){

  int n;
  cin>>n;
  if(!n) break;

  vector <xy> rec(n);

  for(int i=1;i<n;i++){
    int n,direct;
    cin>>n>>direct;
    rec[i].x=rec[n].x+dx[direct];
    rec[i].y=rec[n].y+dy[direct];
  }

  xy min_xy,max_xy;
  for(int i=0;i<n;i++){
    min_xy.x=min(min_xy.x,rec[i].x);
    min_xy.y=min(min_xy.y,rec[i].y);
    max_xy.x=max(max_xy.x,rec[i].x);
    max_xy.y=max(max_xy.y,rec[i].y);
  }

  cout<<max_xy.x-min_xy.x+1<<" "<<max_xy.y-min_xy.y+1<<endl;

  }

  return 0;

}



Measured memory_bytes: 2968
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int64 a, b;
  cin >> a >> b;
  int ret = 0;
  while (a <= b) {
    ++ret;
    a *= 2;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
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];
		int sum = 0;
		int befPlace = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			sum += Math.abs(a[i] - befPlace);
			befPlace = a[i];
		}
		sum += Math.abs(0 - befPlace);

		int diff = 0;
		int befPlace2 = 0;
		int nextPlace = 0;
		for (int i = 0; i < n; i++) {
			nextPlace = (i == n - 1) ? 0 : a[i + 1];
			int shortCut = Math.abs(befPlace2 - nextPlace);
			int normal = Math.abs(befPlace2 - a[i]) + Math.abs(a[i] - nextPlace);
			diff = normal - shortCut;
			System.out.println(sum - diff);
			befPlace2 = a[i];
		}
	}

}


Measured memory_bytes: 55224