akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right) {
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for (i = 0; i < n1; i++) L[i] = A[left + i];
    for (i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for (k = left; k < right; k++) {
        if (L[i].value <= R[j].value) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right) {
    int mid;
    if (left + 1 < right) {
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r) {
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for (j = p; j < r; j++) {
        if (A[j].value <= x.value) {
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i + 1];
    A[i + 1] = A[r];
    A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r) {
    int q;
    if (p < r) {
        q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main() {
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n - 1);

    for (i = 0; i < n; i++) {
        if (A[i].suit != B[i].suit) stable = 0;
    }

    if (stable == 1)
        printf("Stable\n");
    else
        printf("Not stable\n");
    for (i = 0; i < n; i++) {
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}


Measured memory_bytes: 4956
#include <iostream>

using namespace std;

int main(void)
{
	int tou, jiao;
	cin >> tou >> jiao;
	if (jiao&1) { cout << "No"; return 0; }
	if (tou * 2 > jiao) { cout << "No"; return 0; }
	if (tou * 4 < jiao) { cout << "No"; return 0; }
	cout << "Yes";

	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	int H, W;
	cin >> H >> W;

	vector<string> row;
	vector<string> column(W, "");

	string str;

	for (int i = 0; i < H; i++) {
		cin >> str;
		if (str.find('#', 0) == string::npos) {
			continue;
		}
		else {
			row.push_back(str);
			for (int j = 0; j < W; j++) {
				column[j] += str.substr(j, 1);
			}
		}
	}

	for (int j = W - 1; j >= 0; j--) {
		if (column[j].find('#', 0) == string::npos) {
			for (int i = 0; i < row.size(); i++) {
				row[i].erase(j,1);
			}
		}
	}

	for (int i = 0; i < row.size(); i++) {
		cout << row[i] << endl;
	}

	return 0;
}



Measured memory_bytes: 384
import Data.List
import Data.Array

main = do
  n:k:_ <- map read . words <$> getLine :: IO [Int]
  r:s:p:_ <- map read . words <$> getLine :: IO [Integer]
  t <- getLine :: IO String
  putStrLn $ show $ score [r, s, p] k n t

foldlState :: (c -> a -> b -> (c, a)) -> c -> a -> [b] -> a
foldlState f s a l = snd $ foldl (\(s,a) -> f s a) (s, a) l

score :: [Integer] -> Int -> Int -> String -> Integer
score rsp k n t = foldlState step (-1, 3) 0 $ sortBy myCompare $ zip [ mod i k | i <- [0..n-1] ] $ map foo t
    where foo 'r' = 2
          foo 's' = 0
          foo 'p' = 1
          step prev a cur = if prev == cur
                            then ((fst prev, 3), a)
                            else (cur, a + (rsp !! snd cur))

myCompare x y
    | fst x < fst y = LT
    | fst x > fst y = GT
    | otherwise = EQ


Measured memory_bytes: 29052
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n, k, s;
  cin >> n >> k >> s;
  int dm;
  if(s == 1e9){
    dm = 1;
  }else{
    dm = s+1;
  }
  rep(i, n){
    if(i < k) cout << s << " ";
    else cout << dm << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1280
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

from math import gcd
n=n0()
s=0
for a in range(1,n+1):
    for b in range(a,n+1):
        for c in range(b,n+1):
            if a==b==c:
                s+=gcd(gcd(a,b),c)
            elif a==b or b==c:
                s+=3*gcd(gcd(a,b),c)
            else:
                s+=6*gcd(gcd(a,b),c)
print(s)

Measured memory_bytes: 9224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

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

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

#define amari(x) ((x) % 1000000007)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end());
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>());
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin();
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin();

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

int n;
long a[200000];
long scores[100001];

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

  cin >> n;

  string s;
  cin >> s;

  int cnt = 0;

  rep(i, n) {
    if (s[i] == 'R') {
      cnt++;
    } else {
      cnt--;
    }
  }

  if (cnt > 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


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

namespace CSharpSample01
{
    
    class Program
    {


        
        static void Main(string[] args)
        {            

            while (true)
            {
                string sentence = Console.ReadLine();

                if (sentence == ".") break;

                Stack<char> stack = new Stack<char>();

                bool is_correct = true;

                for(int i = 0; i < sentence.Length; i++)
                {
                    
                    if(sentence[i] == '(' || sentence[i] == '[')
                    {
                        stack.Push(sentence[i]);
                    }
                    else if(sentence[i] == ')')
                    {
                        if(stack.Count() == 0)
                        {
                            is_correct = false;
                        }
                        else
                        {
                            char c = stack.Pop();
                            if(c != '(')
                            {
                                is_correct = false;
                            }
                        }
                    }
                    else if(sentence[i] == ']')
                    {
                        if (stack.Count() == 0)
                        {
                            is_correct = false;
                        }
                        else
                        {
                            char c = stack.Pop();
                            if (c != '[')
                            {
                                is_correct = false;
                            }
                        }
                    }
                    

                    if (!is_correct)
                    {
                        break;
                    }
                    
                }

                if (is_correct && stack.Count() == 0)
                {
                    Console.WriteLine("yes");                   
                }
                else
                {
                    Console.WriteLine("no");                                       
                }

                
                
            }
            
        }
    }
}


Measured memory_bytes: 16536
n = int(input())
ans = 0
score = []
for _ in range(n):
    score.append(int(input()))

score.sort()
total = sum(score)
if total % 10 == 0:
    for s in score:
        if s % 10 != 0:
            total -= s
            break

print(total if total % 10 != 0 else 0)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
int main(){
  long long n;
  cin>>n;

  
  string str="";
  while(n>0){
    str.push_back('a'+(n+25)%26);
    n=(n-1)/26;
  }
  
  cout<<string(str.rbegin(),str.rend())<<endl;
  return(0);
}

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

int main()
{
  int N;
  bool flag=false;
  string S;
  
  cin >> N;
  for (int i=0; i<N; i++)
  {
    cin >> S;
    if (S=="Y")
    {
      flag = true;
    }
  }
  if (flag)
  {
    cout << "Four" << endl;
  }
  else
  {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 3572
/* 
   AOJ 2019
   Princess's Marriage
   2015/6/10
*/

#include<stdio.h>
#include<stdlib.h>



struct node
{
  int distance, probably;
  struct node *next;
};

struct node *head = NULL;


void trav(void)
{
  struct node *next;
  for(next = head; next != NULL; next = next->next)
    {
      printf("%d->", next->probably);
    }
  printf("\n");
}


void create_list(int distance, int probably)
{
  struct node *new = malloc(sizeof(*new)), *prev, *next;


  new->distance = distance;
  new->probably = probably;

  if(head == NULL)
    {
      head = new;
      new->next = NULL;
    }
  else
    {
      next = head;
      prev = head;
      while(next != NULL && probably < next->probably)
      	{
	  /* printf("next->pro = %d", next->probably); */
	  /* fflush(stdout); */
	  prev = next;
	  next = next->next;
	  /* printf("hoge"); */
	  /* fflush(stdout); */
	}
      if(next == head)
	{
	  head = new;
	  new->next = next;
	  return;
	}
      prev->next = new;
      new->next = next;
    }
  /* trav(); */
}

int calc_prob(int estimate, int sum_prob)
{
  struct node *next;
  int i;
  for(next = head; next != NULL; next = next->next)
    {
      
      for(i = 0; estimate > 0 && i < next->distance; i++)
	{
	  //	  printf("%d->", next->probably);
	  sum_prob -= next->probably;
	  estimate--;
	  //	  printf("sum_prob %d estimate %d\n", sum_prob, estimate);
	}
    }
  //  printf("\n");
  return sum_prob;

}

/* void free(void) */
/* { */
/*   struct node *point = head, *prev; */
/*   while(1) */
/*     { */
/*       prev = point; */
/*       point = point->next; */
      
/*     } */
/* } */

int main(void)
{
  int section_num, estimate, distance, probably, i, j, sum = 0;
  while(1)
    {
      scanf("%d %d", &section_num, &estimate);
      if(section_num == 0 && estimate == 0)
	{
	  break;
	}
      for(i = 0; i < section_num; i++)
	{
	  scanf("%d %d", &distance, &probably);
	  sum += probably * distance;
	  /* printf("-----%d\n", sum); */
	  create_list(distance, probably);
	}

      printf("%d\n" ,calc_prob(estimate, sum));
      sum = 0;
      head = NULL;
      /* trav(); */
    }
  return 0;
}

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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var H = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

            var ans = 0;
            var tmp = 0;
            for (int i = 0; i < N - 1; i++)
            {
                if (H[i] - H[i + 1] < 0)
                {
                    tmp = 0;
                    continue;
                }

                tmp += 1;
                if (tmp > ans)
                {
                    ans = tmp;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 25692
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using ll =long long;

bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int ab(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  int n;
  cin>>n;
  
  cout << n*n*n <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sf(a) scanf("%d",&a)
#define MX 100000
#define inf 1e9
#define m_p make_pair
#define pb push_back
#define mem(x,val) memset(x,val,sizeof(x))
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define FAST  ios_base::sync_with_stdio(0);cout.tie(0)
#define sqr(x) ((x)*(x))
#define MOD 100000

int lps[MX];
void failure_table(string str){

    lps[0] = 0;
    lps[1] = 0;
    int m = str.size();
    for(int i=2;i<=m;i++){
        int j=lps[i-1];
        while(true){
            if(str[j]==str[i-1]){
                lps[i] = j+1;
                break;
            }
            if(j==0){
                lps[i] = 0;
                break;
            }
            j = lps[j];
        }
    }

}
vector<int> v;
void KMP(string text, string pat){

    int i=0;
    int j=0;
    int n = text.size();
    int m = pat.size();
    while(true){
        if(j==n){
            break;
        }

        if(text[j]==pat[i]){
            j++;
            i++;
            if(i==m){
                v.push_back(j-i);
            }
        }
        else {
            if(i==0) j++;
            else i = lps[i];
        }

    }
}


int main() {

    string pat,text;
    getline(cin, text);
    getline(cin, pat);
    failure_table(pat);
    KMP(text,pat);

    for(auto x:v){
        cout << x << endl;
    }

    return 0;
}



Measured memory_bytes: 9272
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int ans = 0;
vector<array<int,4>>v;
int n,m,q;

void solve(vector<int>a){
	if(a.size()==n){
		int curr = 0;
		for(int i=0;i<q;i++){
			if((a[v[i][1]] - a[v[i][0]])==v[i][2]) curr+=v[i][3];
		}
		ans = max(ans,curr);
		return ;
	}
	for(int j=a.back();j<=m;j++){
		vector<int>c = a;
		c.push_back(j);
		solve(c);
	}
}

int32_t main(){
	fastio();
	
	cin>>n>>m>>q;
	
	for(int i=0;i<q;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		a--,b--;
		v.push_back({a,b,c,d});
	}
	for(int i=1;i<=m;i++){
		vector<int>c;
		c.push_back(i);
		solve(c);
	}
	cout<<ans;
}

Measured memory_bytes: 3652
H,W=map(int,input().split())
C=[ list(map(int,input().split())) for i in range(10)]
A=[ list(map(int,input().split())) for i in range(H) ] 

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
n=10
B=warshall_floyd(C)
  
ans=0
for i in range(H):
  for j in range(W):
    if A[i][j]!=-1:
      ans+=B[ A[i][j] ][1]
print(ans)


Measured memory_bytes: 40284
#include <stdio.h>

int num,A[2000];


int main(){
  int i,j;
  int q;
  int m[2000];

  scanf("%d",&num);
  for(i=0;i<num;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);
  }

  
  for(i=0;i<q;i++){
    if(1==solve(0,m[i]))printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
  
}
    
int solve(int i, int m){
  int res;
  if( m == 0){
    return 1;
  }


  if( i >= num){
    return 0;
  }
  
  res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}
  



Measured memory_bytes: 2052
n = int(input())
a = list(map(int , input().split()))
ans = []
a.sort()
a.reverse()
f = 0
cnt = 1
when = 0
for i in a:
    if i == f:
        cnt += 1
        if cnt >= 2:
            ans.append(i)
            cnt = 0
            when += 1
    else:
        f = i
        cnt = 1
    if when == 2:
        break
if len(ans) != 0:
    print(ans[0] * ans[1])
else:
    print(0)

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

typedef long long ll;
typedef long long ld;
typedef vector<int> vi;
typedef priority_queue<int> pq;
typedef pair<ll, ll> pii;

struct Node
{
    int node, len;
    Node() {node = len = 0;}
    Node(int node, int len) {this -> node = node, this -> len = len;}
};
typedef vector<Node> vg;

#define MAX 20
#define NON 0
#define MOD 1000000007

#define FOR(type, i, a, b) for(type i = a; i <= b; i++)
#define FORR(type, i, b, a) for(type i = b; i >= a; i--)

#define testBit(n, bit) ((n >> bit) & 1)
#define flipBit(n, bit) (n ^ (1ll << bit))
#define randomize mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

int n, m, x;
int c[MAX];
int a[MAX][MAX];
int val[MAX];
int ans = INT32_MAX;

void test(int book, int sum){
    if (book > n){
        bool ok = true;
        FOR(int, i, 1, m)
            if (val[i] < x){ok = false; break;}
        if (ok) ans = min(ans, sum);
        return;
    }
    test(book + 1, sum);
    FOR(int, i, 1, m) val[i] += a[book][i];
    test(book + 1, sum + c[book]);
    FOR(int, i, 1, m) val[i] -= a[book][i];
}

main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> x;
    FOR(int, i, 1, n){
        cin >> c[i];
        FOR(int, j, 1, m) cin >> a[i][j];
    }
    test(1, 0);
    if (ans == INT32_MAX) cout << -1;
    else cout << ans;
}

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

#define rep(i, n) for(int (i) = 0; i < (n); ++(i))

typedef long long ll;
const ll MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
  std::string S;
  std::cin >> S;

  int N = (int) S.length();
  int cnt[MAX_N];
  rep(i, N) cnt[i] = 1;
  rep(i, N) {
    if(S[i] == 'R' and S[i + 1] == 'R') {
      cnt[i + 2] += cnt[i];
      cnt[i] = 0;
    }
  }
  rep(i_, N) {
    int i = N - 1 - i_;
    if(S[i] == 'L' and S[i - 1] == 'L') {
      cnt[i - 2] += cnt[i];
      cnt[i] = 0;
    }
  }

  rep(i, N) {
    std::cout << cnt[i] << ' ';
  }
}


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

int main(void){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    while(true){
        C -= B;
        if(C <= 0){
            cout << "Yes" << endl;
            return 0;
        }
        A -= D;
        if(A <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3636
#include<iostream>
#include<fstream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<typeinfo>
using namespace std;

int main(){
    int N;
    cin >> N;
    cout << 800*N - 200*(N/15) << endl;
    return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;


int main(){
  ll n;
  cin >> n;
  vector<ll> p(n);
  rep(i, n) cin >> p[i];


  vector<ll> q = p;
  sort(all(q));

  ll cnt = 0;
  rep(i, n){
    if(p[i] != q[i]) cnt++;
  }

  if(cnt <= 2) cout << "YES" << endl;
  else         cout << "NO" << endl;


  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll read()
{
	ll f=1,x=0;
	char ch=getchar();
	while(!isdigit(ch)){if(ch=='-'){f=-1;}ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
ll n,c,f[405][405],l[405][405],sum[405][405],a[405],b[405];
int main()
{
	n=read();
	c=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++)b[i]=read();
	for(int i=1;i<405;i++)
	{
		l[i][0]=1;
		for(int j=1;j<405;j++)
		{
			l[i][j]=l[i][j-1]*i;
			l[i][j]%=mod;
		}
	}
	for(int i=1;i<405;i++)
	{
		for(int j=0;j<405;j++)
		{
			sum[i][j]=sum[i-1][j]+l[i][j];
			sum[i][j]%=mod;
		}
	}
	f[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		 for(int j=0;j<=c;j++)
		 {
		 	for(int k=0;k<=j;k++)
			{
				f[i][j]=(f[i][j]%mod+(f[i-1][j-k]*(sum[b[i]][k]-sum[a[i]-1][k])%mod+mod))%mod;
			}
		}
	}	
	cout<<f[n][c];
	return  0;	
}
	

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

    public static void main(String[] args) {
        Scanner yomi = new Scanner(System.in);
        byte toshi = yomi.nextByte();
        byte A,B;
        if (toshi == 1) System.out.println("Hello World");
        else {
            A = yomi.nextByte();
            B = yomi.nextByte();
            System.out.println(A + B);
        }
        
    }
}


Measured memory_bytes: 21972
#include<stdio.h>
#include <bits/stdc++.h>
using namespace std;
#include<stdbool.h>
#include<math.h>
#include<string.h>
#define ll long long
#define db double
#define max(a, b) a>b?a:b
#define min(a, b) a<b?a:b
#define sz 500000005


int main()
{
    ll n, k, p[1005], i, sum=0;
    scanf("%lld %lld", &n, &k);
    for(i=0; i<n; i++)
        scanf("%lld", &p[i]);
    sort(p, p+n);
    for(i=0; i<k; i++)
        sum+=p[i];
    printf("%lld", sum);
    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;  //firstは最短距離,secondは頂点番号

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

struct edge{
	int to,cost;
	edge(){to=0;cost=0;}
};

class dijkstra{
public:
	vector<vector<edge> > E;
	vector<int> dist;
	int start;
	dijkstra(int n): E(n),dist(n){}

	void add_edge(int x,int y,int c){
		edge e;
		e.to = y,e.cost = c;
		E[x].push_back(e);
	}

	void shortest_path(){
		priority_queue<P,vector<P>,greater<P> > que;
		dist.assign(dist.size(),INF);

		dist[start] = 0;
		que.push(P(0,start));

		while(!que.empty()){
			 P p = que.top();
			 que.pop();
			 int v = p.second;
			 if(dist[v] < p.first) continue;

			 for(int i = 0; i < E[v].size(); i++){
			 	edge e = E[v][i];
			 	if(dist[v] +  e.cost < dist[e.to]){
			 		dist[e.to] = dist[v] +  e.cost;
			 		que.push(P(dist[e.to],e.to));
			 	}
			 }
		}
	}


};

int main()
{
	int n;
	cin >> n;
	dijkstra dij(n);
	for(int i = 0; i < n; i++){
		int u,k;
		cin >> u >> k;
		for(int j = 0; j < k; j++){
			int v,c;
			cin >> v >> c;
			dij.add_edge(u,v,c);
		}
	}

	dij.start = 0;
	dij.shortest_path();

	for(int i = 0; i < n; i++){
		cout << i << " " <<  dij.dist[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3132
#include <iostream>
using namespace std;
#define LL long long

#include <cmath>
void _140() {
    int n;
    cin >> n;
    int b[100];
    LL sum = 0;
    for (int i = 0; i < n - 1; ++i) {
        cin >> b[i];
        if (i == 0) {
            sum += b[i];
        } else {
            sum += min(b[i - 1], b[i]);
        }
    }
    sum += b[n - 2];

    cout << sum << endl;
}

void _141() {
    int n, k, q;
    cin >> n >> k >> q;
    int a[100000];
    int point[100000] = {0};
    for (int i = 0; i < q; ++i) {
        cin >> a[i];
        point[a[i] - 1]++;
    }

    for (int i = 0; i < n; ++i) {
        if (k + point[i] - q > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
 }

int main()
{
    _141();

    return 0;
}



Measured memory_bytes: 1408
a[200],b[200],c[1000],d[1000],n,m,i,j,k,t;main(){for(;;){scanf("%d",&n);if(n==0)break;for(i=0;i<n;i++){scanf("%d%d",&a[i],&b[i]);}scanf("%d",&m);for(i=0;i<m;i++){scanf("%d%d",&c[i],&d[i]);}for(i=0;i<m;i++){for(j=1;j<n;j++){for(k=0;k<m;k++){if(a[j]+c[i]-a[0]==c[k]){if(b[j]+d[i]-b[0]==d[k]){t++;break;}}}}if(t==n-1){printf("%d %d\n",c[i]-a[0],d[i]-b[0]);t=0;break;}t=0;}}return 0;} 

Measured memory_bytes: 608
n = int(input())
a = [0] + list(map(int,input().split())) + [0]
c = []
total = 0
for i in range(n+1):
    tmp = abs(a[i+1] - a[i])
    c.append(tmp)
    total += tmp

for i in range(1,n+1):
    ans = total - c[i-1] - c[i] + abs(a[i+1] - a[i-1])
    print(ans)

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

#include<iostream>
#include<string>

bool judge(string s) {
  return "01" <= s && s <= "12"; 
}

int main() {
  string S;
  cin >> S;
  string A = S.substr(0,2);
  string B = S.substr(2,2);
  //cout << A << B << endl;
  if (judge(A) && judge(B)) {
    cout << "AMBIGUOUS" << endl;
  } else if (judge(A)) {
    cout << "MMYY" << endl;
  } else if (judge(B)) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }

  return 0;
}

Measured memory_bytes: 3556
// https://atcoder.jp/contests/abc161/tasks/abc161_e
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K, C;
    cin >> N >> K >> C;
    string s;
    cin >> s;
    vector<int> L, R;
    REP(i, N) {
        if (s[i] == 'o') {
            L.push_back(i);
            i += C;
        }
    }
    for (int i = N - 1; i >= 0; i--) {
        if (s[i] == 'o') {
            R.push_back(i);
            i -= C;
        }
    }
    if (K != (int)L.size()) {
        return 0;
    }
    reverse(ALL(R));
    REP(i, L.size()) {
        if (L[i] == R[i]) {
            cout << L[i] + 1 << "\n";
        }
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc() {
	ll k, n;
	ll ans = 0;

	cin >> k >> n;

	V a(n);
	rep(i, n) {
		cin >> a[i];
	}


	vector<P> d(n);
	rep(i, n - 1) {
		d[i] = make_pair(a[i + 1] - a[i], i);
	}
	d[n - 1] = make_pair(a[0] + k - a[n - 1], n - 1);

	sort(ALL(d));

	ans = k - d[n - 1].first;

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

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

	solve_abc();

	return 0;
}

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

void insertionSort(vector<int> &a,int n);

int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n){
    cin>>a[i];
  }
  
insertionSort(a,n);
  
}

void insertionSort(vector<int> &a,int n){
  int v;
  rep(k,n-1){
      cout<<a[k]<<" ";
    }
    cout<<a[n-1];
  for(int i=1;i<n;i++){
    cout<<endl;
    v=a[i];
    int j=i-1;
    while(j>=0&&a[j]>v){
      a[j+1]=a[j];
      j--;
    }
     a[j+1]=v;
     rep(k,n-1){
      cout<<a[k]<<" ";
    }
    cout<<a[n-1];
  }
  cout<<endl;
}



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

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

Measured memory_bytes: 384
N,M=map(int,input().split())

ans=[]

def dfs(num,count,visit):
    #print(num,visit)
    if count==N:
        if len(visit)==N:
            ans.append(num)
        
    else:
        for index,item in enumerate(l[num]):
            if item==1 and visit.count(index)==0:
                dfs(index,count+1,visit+[index])
    return 0

            
        

l=[[0]*N for i in range(N)]

for _ in range(M):
    a,b=map(int,input().split())
    l[a-1][b-1]=1
    l[b-1][a-1]=1

dfs(0,1,[0])

print(len(ans))
#print(ans)



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


int find( int* a , int val , int n){
    int s = 1, t = n+1;
    while( t - s > 1){
	int mid = ( s + t )/2;
	if( a[ mid ] == val ) return 1;
	else if( a[ mid ] > val ){
	    t = mid;
	}else{
	    s = mid;
	}
    }
    if( a[s] == val ) return 1;
    return 0;
}

int main(){
    int a[ 100000 + 1 ];
    int n;
    scanf("%d",&n);
    *a = n;
    int i;
    for(i=1;i<=n;i++) scanf("%d",a+i);
    int q;
    scanf("%d",&q );
    for(i=0;i<q;i++){
	int k;
	scanf("%d",&k);
	if( find( a, k , n ) ) printf("1\n");
	else printf("0\n");
    }

    return 0;
}



Measured memory_bytes: 2964
# 入力 : Nセットの3個の数字
N = int(input())
list = [0 for i in range(0,N+1)]
list[0] = (0,0,0)
for i in range(0,N) :
    a, b, c = map(int, input().split())
    list[i+1] = (a,b,c)

can = True

for i in range(1,N+1):
    time = list[i][0] - list[i-1][0]
    dist = abs(list[i][1] - list[i-1][1]) + abs(list[i][2] - list[i-1][2])
    if dist > time :
        can = False
        break
    elif time%2 != dist%2 :
        can = False
        break
    else :
        continue        

if can == True :
    print("Yes")
else :
    print("No")


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

int main(){
    int n, m;
    cin >> n >> m;
    int cnt[100001] = {};
    int a;
    for(int i = 0; i < 2*m; i++) cin >> a, cnt[a]++;
    for(int i = 0; i < 100001; i++){
        if(cnt[i]%2){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

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

typedef long long ll;

const long double PI = (acos(-1));

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

  int n;
  cin >> n;

  int h0, h;
  int ans = 0, temp = 0;
  cin >> h0;
  for (int i = 0; i < n - 1; i++){
    cin >> h;
    if (h0 >= h){
      temp++;
      if (ans < temp) ans = temp;
    }else {
      temp = 0; 
    }
    h0 = h;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import math
A, B, N = [int(x) for x in input().split(" ")]

def func(A, B, x):
    return math.floor(A*x/B) - A * math.floor(x/B)
    
if B > N:
    print(func(A, B, N))
elif B == N:
    print(func(A, B, N - 1))
else:
    print(func(A, B, B - 1))

Measured memory_bytes: 62076
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps DBL_EPSILON
#define moder 10007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n,a[10010],b[10010],suma,sumb,kaisu,cnt1,cnt2;
signed main(){
	cin>>n;
	rep(i,n){
		cin>>a[i];
		suma+=a[i];
	}
	rep(i,n){
		cin>>b[i];
		sumb+=b[i];
	}
	kaisu=sumb-suma;
	rep(i,n){
		if(a[i]>b[i])cnt1+=a[i]-b[i];
		else cnt2+=(b[i]-a[i]+1)/2;
	}
	if(kaisu<cnt1||kaisu<cnt2)puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 384
use std::collections::VecDeque;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

const MOD: i64 = 1_000_000_007;

fn main() {
    let (h, w) = scan!(usize, usize);
    let graph = scan!(;;h);
    let mut nums = vec![vec![0; w]; h];
    nums[0][0] = 1;

    let mut q = VecDeque::new();
    q.push_back((0, 0));
    while let Some((x, y)) = q.pop_front() {
        if !(x == 0 && y == 0) && nums[x][y] != 0 {
            continue;
        }

        if x + 1 < h && graph[x + 1].chars().nth(y).unwrap() != '#' {
            q.push_back((x + 1, y))
        }
        if y + 1 < w && graph[x].chars().nth(y + 1).unwrap() != '#' {
            q.push_back((x, y + 1))
        }

        if !(x == 0 && y == 0) {
            nums[x][y] =
                if x >= 1 { nums[x - 1][y] } else { 0 } + if y >= 1 { nums[x][y - 1] } else { 0 };
            nums[x][y] %= MOD;
        }
    }
    println!("{}", nums[h - 1][w - 1])
}


Measured memory_bytes: 12668
<?php
$S=trim(fgets(STDIN));
$Q=trim(fgets(STDIN));
$p='';
for($I=0;$I<$Q;$I++){
  $C=explode(' ',trim(fgets(STDIN)));

  if($C[0]=='print'){
    for($i=$C[1];$i<=$C[2];$i++) $p.=$S[$i];
    $p.=PHP_EOL;
    continue;
  }
  if($C[0]=='reverse'){
    $l=($C[2]-$C[1]+1)>>1;
    for($i=0;$i<$l;$i++){
      $j=$C[2]-$i;
      $k=$C[1]+$i;
      $s=$S[$j];
      $S[$j]=$S[$k];
      $S[$k]=$s;
    }
    continue;
  }
  for($i=$C[1];$i<=$C[2];$i++) $S[$i]=$C[3][$i-$C[1]];
}
print $p;

Measured memory_bytes: 15592
n = int(input())
s = []
for i in range(n):
    s.append(int(input()))

if sum(s) % 10 != 0:
    print(sum(s))
else:
    s.sort()
    for i in range(n):
        if s[i] % 10 == 0:
            pass
        else:
            print(sum(s) - s[i])
            break
    else:
        print(0)


Measured memory_bytes: 9136
#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() {
  ll a,b,c,d=4;
  cin >> a >> b >> c;
  ll t=c-a-b;
  if (c-a-b<0) cout << "No" << endl;
  else{
    if (4*a*b<t*t) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


Measured memory_bytes: 256
/**


太郎と花子がカードゲームをする。二人はそれぞれn枚のカードを持っており、nターンの勝負を行う。
各ターンではそれぞれ１枚ずつカードを出す。カードにはアルファベットからなる動物の名前が書かれており
辞書順で大きいものがそのターンの勝者となる。
勝者には３ポイント、引き分けの場合にはそれぞれ１ポイントが加算される。
太郎と花子の手持ちのカードの情報を読み込み、ゲーム終了後のそれぞれの得点を出力するプログラムを作成せよ。

 */

//スキャナつかうため

import java.util.Scanner;

public class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成

		Scanner sc = new Scanner(System.in);
		//ターン数を受け取る
		int intTrun = sc.nextInt();
		//受け取る文字、保持するポイントの変数宣言
		String Hanaco;
		String Taro;
		int intHanacop = 0;
		int intTarop = 0;
		//ターンの数だけ処理を繰り返す
		for (int i = 0; i < intTrun; i++) {
			//数値を受け取る
			Taro = sc.next();
			Hanaco = sc.next();

			// System.out.println(Taro + Hanaco + intHanacop);
			//文字列TaroがHanacoより辞書順で早い場合
			if (Taro.compareToIgnoreCase(Hanaco) > 0) {
				intTarop += 3;
			//文字列TaroがHanacoより辞書順で遅い場合
			}else if (Taro.compareToIgnoreCase(Hanaco) < 0 ){
				intHanacop += 3;
			//文字列TaroとHanacoが同じ文字列の場合
			}else if (Taro.compareToIgnoreCase(Hanaco) == 0){
				intTarop ++;
				intHanacop ++;
			}

		}
		//結果表示
		System.out.println( intTarop + " " + intHanacop);
	}
}

Measured memory_bytes: 20744
#include<iostream>
#include<cctype>
#include<string>

using namespace std;

int main(){
    string str;
    getline(cin,str);
    for(int i=0;i<str.length();i++){
        if(str[i]>='a'&&str[i]<='z'){
            str[i]=toupper(str[i]);
        }else if(str[i]>='A'&&str[i]<='Z'){
            str[i]=tolower(str[i]);
        }
        cout<<str[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef pair<int,int> ii;
int n;
ii a[200004];
int main()
{
    //freopen("D.in","r",stdin);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        int x,y;
        cin >> x >> y;
        a[i]=ii(y,x);
    }
    sort(a+1,a+1+n);
    long long s=0;
    for (int i=1;i<=n;i++)
    {
        if (s+a[i].S>a[i].F)
        {
            //cout << s+a[i].S << " " << a[i].F << " " << i << "\n";
            cout << "No";
            return 0;
        }
        s+=a[i].S;
        //cout << s << "\n";
    }
    cout << "Yes";
}


Measured memory_bytes: 1792
import sys
def getInput():
    return [int(i) for i in input().rstrip().split(' ')]
def checkBingo(holes):
    holes_x = [list(x) for x in zip(*holes)]
    _a,_b = True,True
    for i in range(3):
        if not None in holes[i] or not None in holes_x[i]:# 縦横
            return True
        #斜め
        if None is holes[i][i]:_a=False
        if None is holes[i][2-i]: _b=False
    return (_a ==True or _b == True)
bingo = []
holes = []
for i in range(3):
    bingo += [getInput()]
for i in bingo:
    holes += [[None for n in i]]
N = getInput()[0]
for i in range(N):
    num = getInput()[0]
    for h in range(3):
        for w in range(3):
            if num == bingo[h][w]:
                holes[h][w] = 1
                break
    if checkBingo(holes):
        print('Yes')
        sys.exit()
print('No')

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
map<string,int> name;
map<string,int>::iterator it;
int main()
{
	
	   int i,n,ss=0;
	   string s;
        cin>>n;
		for(i=0;i<n;i++)
		{
			cin>>s;
			name[s]++;
		    ss=max(ss,name[s]);	
		} 
		for(it=name.begin();it!=name.end();it++)
		{
			if(it->second==ss)
			cout<<it->first<<endl;
		}





}

Measured memory_bytes: 25216
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007
#define pi atan(1) * 4

int n, z, w;
int a[2001];
vector<vector<int> > result(2001, vector<int>(2, -1));

int solve(int index, int player, int score0, int score1)
{
	if(index >= n) return abs(score0 - score1);
	if(result[index][player] != -1) return result[index][player];
	int ans;
	if(player == 0) ans = 0;
	else ans = mod;
	for(int i = index; i < n; i++){
		if(player == 0) ans = max(ans, solve(i + 1, 1, a[i], score1));
		else ans = min(ans, solve(i + 1, 0, score0, a[i]));
	}
	return result[index][player] = ans;
}

int main()
{
	cin >> n >> z >> w;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	cout << solve(0, 0, z, w) << endl;
	return 0;
}

Measured memory_bytes: 512
for Panzerlied in range(0,int(input())):
  runners = 0
  outs = 0
  points = 0
  while outs<3:
    command=input()
    if command == "HIT":
      runners+=1
      if runners > 3:
        runners=3
        points+=1
    elif command == "HOMERUN":
      points+=(runners+1)
      runners=0
    else: # command == "OUT"
      outs+=1
  print(points)

Measured memory_bytes: 7556
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			Integer[] v = new Integer[n];
			for(int i = 0 ; i < n ; i++) {
				v[i] = sc.nextInt();
			}
			Arrays.sort(v);
			BigDecimal mixed = new BigDecimal(v[0].toString());
			for(int i = 1 ; i < n ; i++) {
				mixed = mixed.add(new BigDecimal(v[i].toString())).divide(new BigDecimal("2"));
			}
			System.out.println(mixed.toString());
		}

	}

}


Measured memory_bytes: 21972
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		System.out.print(Math.min(A, B));
		System.out.print(" ");
		System.out.println(Math.max(0, A - (N - B)));
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;
		private StringBuilder buffer = new StringBuilder();

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			int read = skip();
			do {
				buffer.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			String text = buffer.toString();
			buffer.delete(0, buffer.length());

			return text;
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 21076
#include <iostream>
#include <cstdint>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <random>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define loop(i, a, b) for (int i = a; i < (int)(b); i++)


int solve(string l) {
    const ll mod = 1000000007;
    int len = l.length();
    ll count1 = 1;
    ll count2 = 1;

    rep(i, len) {
        char c = l[len - i - 1];
        if (c == '0') {
            count1 = count1;
            count2 = (count2 * 3) % mod;
        } else if (c == '1') {
            count1 = (count1 * 2 + count2) % mod;
            count2 = (count2 * 3) % mod;
        }
    }
    return count1;
}

int main() {
    string s;
    cin >> s;
    int ans = solve(s);
    cout << ans << "\n";
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
using namespace std;
int c[4005][5];
char s[4005];
int main()
{
	int n;
	scanf("%d\n",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
	{
		c[i][1]=c[i-1][1],
		c[i][2]=c[i-1][2],
		c[i][3]=c[i-1][3];
		if(s[i]=='R')
		{
			c[i][1]++;
		}
		if(s[i]=='G')
		{
			c[i][2]++;
		}
		if(s[i]=='B')
		{
			c[i][3]++;
		}
	}
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int k=i+2;k<=n;k++)
		{
			if(s[k]==s[i])continue;
			if(s[i]=='R'&&s[k]=='G')
			{
				ans+=c[k-1][3]-c[i][3];
			}
			else
			if(s[i]=='G'&&s[k]=='R')
			{
				ans+=c[k-1][3]-c[i][3];
			}
			else
			if(s[i]=='R'&&s[k]=='B')
			{
				ans+=c[k-1][2]-c[i][2];
			}
			else
			if(s[i]=='B'&&s[k]=='R')
			{
				ans+=c[k-1][2]-c[i][2];
			}
			else
			if(s[i]=='G'&&s[k]=='B')
			{
				ans+=c[k-1][1]-c[i][1];
			}
			else
			if(s[i]=='B'&&s[k]=='G')
			{
				ans+=c[k-1][1]-c[i][1];
			}
			if((k-i)%2==0)
			{
				int j=(k+i)/2;
				if(s[j]!=s[k]&&s[j]!=s[i])
				ans--;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1788
N,M=gets.split.map &:to_i
require 'prime'
class Integer
  def divisor_list
    return [] if self <= 0
    return [1] if self == 1
    prime_division.map{|e| [*(0..e.last)].map{|v| e.first ** v }}.inject{|res, e| res.map{|t| e.map{|v| t * v}}.flatten}.sort
  end
end
class Array
  def upper_bound(val)
    a = 0
    b = size
    while a < b
      c = (( a + b ) / 2 ).to_i
      if val < at(c)
        b = c
      else
        a = c + 1
      end
    end
    b
  end
  def lower_bound(val)
    a = 0
    b = size
    while a < b
      c = (( a + b ) / 2 ).to_i
      if val <= at(c)
        b = c
      else
        a = c + 1
      end
    end
    b
  end
end
p M.divisor_list.select{|x|x*N<=M}[-1]

Measured memory_bytes: 3964