akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static int[][] ask;
	public static int n;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		ask = new int[n + 1][n + 1];
		for(int i = 0; i < n + 1; i++) {
			for(int j = 0; j < n + 1; j++) {
				ask[i][j] = -1;
			}
		}
		for(int i = 1; i < n + 1; i++) {
			int a = sc.nextInt();
			for(int j = 0; j < a; j++) {
				int b = sc.nextInt();
				ask[i][b] = sc.nextInt();
			}
		}
		int ans = 0;
		for(long i = 0; i < Math.pow(2, n); i++) {
			int[] calc = new int[n + 1];
			long tmp = i;
			for(int j = 1; j < n + 1; j++) {
				if((tmp & 1) == 1) {
					calc[j] = 1;
				} else {
					calc[j] = 0;
				}
				tmp /= 2;
			}
			boolean btmp = true;
			for(int j = 1; j < n + 1; j++) {
				if(calc[j] == 1) {
					for(int k = 1; k < n + 1; k++) {
						if(ask[j][k] != -1 && ask[j][k] != calc[k]) {
							btmp = false;
							break;
						}
					}
				}
			}
			if(btmp) {
				int atmp = 0;
				for(int j = 1; j < n + 1; j++) {
					if(calc[j] == 1)
						atmp++;
				}
				ans = Math.max(ans, atmp);
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 25320
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>

#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define show(x) cout << #x << " = " << x << "\n"
#define mem( a , b ) memset( a , b , sizeof a )
#define popcnt(x) __builtin_popcount(x)
#define all(x) x.begin() , x.end()
#define SZ(a) (int)a.size()
#define ll  long long
#define ld  long double
#define vii vector  <ll>
#define dqi deque   <ll>
#define sii set     <ll>
#define vpi vector  <pii>
#define mii map     <ll,ll>
#define pii pair    <ll,ll>
#define pi pair     <int,int>
#define vss vector  <string>
#define pb  push_back
#define F   first
#define S   second
#define L   length()
#define PI  3.141592654
#define OO (ll)1e18
#define mod(x,m) (x%m + m )%m
using namespace std;
void ONLINE__JUDGE();

pii swapii( pii pr ){ return { pr.S , pr.F }; }
int dx[] = {  0 ,  0 , -1 , +1 , -1 , +1 , -1 , +1 };
int dy[] = { -1 , +1 ,  0 ,  0 , -1 , +1 , +1 , -1 };

const ll MOD = 1e9 + 7;
const ll MAX = 1e7 + 9;

ll x, y; vii deg;
vii adj[MAX]; bool vis[MAX];

ll nPr( ll n , ll r )
{
    ll res = 1;
    for ( int i = n-r+1; i <= n; ++i )
        res *= i , res %= MOD;
    return res%MOD;
}

int main()
{
    FASTIO //ONLINE__JUDGE();

    cin >> x >> y; deg.resize( x+1 );
    for ( int i = 1; i < x; ++i )
    {
        ll a ,b; cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
        deg[b]++;
    }

    ll root = -1;
    for ( int i = 1; i <= x; ++i )
        if ( deg[i] == 0 ){ root = i; break; }


    ll cnt = nPr( y , 1 ); bool ok = 1;
    queue < ll > q; q.push( root );
    while ( !q.empty() )
    {
        ll t = q.front(); q.pop(); vis[t] = 1;
        if ( ok )
        {
            ll n = 0;
            for ( ll i : adj[t] )
                if ( !vis[i] ) q.push( i ) , n++;

            cnt *= nPr( y-1 , n );
            cnt %= MOD;
            ok = 0;
        }
        else
        {
            ll n = 0;
            for ( ll i : adj[t] )
                if ( !vis[i] ) q.push( i ) , n++;
            cnt *= nPr( y-2 , n );
            cnt %= MOD;
        }
    }
    cout << cnt%MOD;
    return 0;
}


void ONLINE__JUDGE()
{
    #ifndef ONLINE_JUDGE
    freopen( "inp.c"         , "r" , stdin  );
    //freopen( "OutPut.txt"   , "w" , stdout );
    #endif // ONLINE_JUDGE
}



Measured memory_bytes: 241780
N, X = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
x.push(X).sort!

di = Array.new(N)
for i in 0..(N-1)
  di[i] = x[i+1] - x[i]
end

gcd = di[0]
for i in 1..(N-1)
  div = [gcd, di[i]].min
  while div > 0
    if gcd % div == 0 && di[i] % div == 0
      break
    end
    div -= 1
  end
  gcd = div
end
puts gcd

Measured memory_bytes: 12280
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define MOD 1000000007
#define enld endl
typedef long long ll;
using namespace std;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n; cin >> n;
    int ac = 0, wa = 0, tle = 0, re = 0;
    for(int i=0;i<n;i++){
        string s; cin >> s;
        if(s == "AC") ac++;
        else if(s == "WA") wa++;
        else if(s == "TLE") tle++;
        else if(s == "RE") re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

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

long long N;
long long A[200005];
vector<long long> tree[200005];
long long dp[200005];
long long ans[200005];

//dp[i]:= 長さが i+1 であるような増加部分列における最終要素の最小値(存在しない場合は INF)
void dfs(long long pa, long long cur){
	//cout << "pa " << pa << " cur " << cur << endl;
	long long num = A[cur];

	auto it = lower_bound(dp, dp+N, num);
	long long old = *it;
	*it = num;
	ans[cur] = lower_bound(dp, dp + N, LONG_MAX) - dp;
	for(long long i = 0; i < tree[cur].size(); i++) {
		if(tree[cur][i] != pa) {
			dfs(cur, tree[cur][i]);
		}
	}
	*it = old;
}

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

	for(long long i = 0; i < N - 1; i++) {
		long long u,v ;
		cin >> u >> v;
		u--;v--;
		tree[u].push_back(v);
		tree[v].push_back(u);
	}

	fill(dp, dp + N, LONG_MAX);
	dfs(-1, 0);

	for(long long i = 0; i < N; i++) {
		cout << ans[i] << endl;
	}
}



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

int main() {
  int a;
  string b;
  string c;
  cin >> a;
  cin >> b;
  cin >> c;
  int d = 0;
  while(d < a){
    cout << b.at(d);
    cout << c.at(d);
    d = d + 1;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  string s;
  cin >> s;
  string ans = "";
  int n = s.size();
  rep(i, n) {
    char c = s[i];
    switch(c) {
      case '0': {
        ans.push_back('0');
        break;
      }
      case '1' : {
        ans.push_back('1');
        break;
      }
      case 'B' : {
        if(ans != "") ans.pop_back();
        break;
      }
    }
  }   
  cout << ans << endl;
  return 0;
}

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

namespace ITP1_2_D
{
    class Program
    {
        static void Main(string[] args)
        {
            //長方形　左下の頂点(0,0)、右上の頂点(W,H)
            //円　中心座標(x,y)、半径r
            //長方形の中に円が含まれればYes、一部でも含まれなければNoを出力

            string[] i = Console.ReadLine().Split(' ');
            int W = int.Parse(i[0]);
            int H = int.Parse(i[1]);

            int x = int.Parse(i[2]);
            int y = int.Parse(i[3]);
            int r = int.Parse(i[4]);

            if (r <= y && y <= H - r && r <= x && x <= W - r)  
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}



Measured memory_bytes: 17924
using System;

class Program
{
    static public void Main(string[] args)
    {
        int temp = 0, ans = 0;
        int n = int.Parse(Console.ReadLine());
        string input = Console.ReadLine();
        for(int i = 0; i < n; i++)
        {
            if (input[i] == 'I') temp++;
            else temp--;
            ans = Math.Max(ans, temp);
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 2648
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
const li inf = 1e14;
// 12
void _main(int tc) {
  int n, W, sumV = 0;
  cin >> n >> W;
  vector<int> w(n), v(n);
  rep(i, n) {
    cin >> w[i] >> v[i];
    sumV += v[i];
  }

  vector<vector<li>> mem(n, vector<li>(sumV + 1, -1));
  

  function<li(int, int)> knapsack2 = [&](int i, int V) -> li {
    if (V == 0) return 0;
    if (i == n && V != 0) return inf;
    if (mem[i][V] != -1) return mem[i][V];
    if (V - v[i] >= 0)
      mem[i][V] = min(w[i] + knapsack2(i + 1, V - v[i]), knapsack2(i + 1, V));
    else
      mem[i][V] = knapsack2(i + 1, V);
    return mem[i][V];
  };

  rrep(i, sumV + 1) {
    if (knapsack2(0, i) <= W) {
      cout << i << endl;
      break;
    }
  }

  // vector<vector<li>> mem(n + 1, vector<li>(sumV + 1, inf));

  // rep(i, n + 1) mem[i][0] = 0;

  // rrep(i, n) {
  //   rrep(V, sumV + 1) {
  //     if (V - v[i] >= 0)
  //       mem[i][V] = min(w[i] + mem[i + 1][V - v[i]], mem[i + 1][V]);
  //     else
  //       mem[i][V] = mem[i + 1][V];
  //   }
  // }

  // rrep(i, sumV + 1) {
  //   if (mem[0][i] <= W) {
  //     cout << i << endl;
  //     break;
  //   }
  // }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0);
  return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 79488
#include <iostream>
using namespace std;
 
int main(){
    int x,y;
    cin >> x >> y;
    while(!(x==0&&y==0)){
        if(x<y) cout << x << " " << y << endl;
        else cout << y << " " << x << endl;
        cin >> x >> y;
    }
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>
#include <atcoder/fenwicktree>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif


int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);

    int n, q; std::cin >> n >> q;

    atcoder::fenwick_tree<long long int> BIT(n);
    for(int i = 0; i < n; ++i){ int a; std::cin >> a; BIT.add(i, a); }
    while(q--){
        char c; int a, b; std::cin >> c >> a >> b;
        if(c == '0') BIT.add(a, b);
        else std::cout << BIT.sum(a, b) << '\n';
    }
    
    
    return 0;
}

Measured memory_bytes: 8260
#include <iostream>
#include <math.h>
#include<stdio.h>
using namespace std;

int main() {
  int i,j,k;
  int N, D;
  cin >> N >> D;
  int a[N][D];
  for (int i = 0; i < N; ++i) {
    for(int j=0;j<D;++j){
      cin >> a[i][j];
    }
  }
  int cnt=0;
  double sum;
  for (i=0;i<N;++i){
    for (j=i+1;j<N;++j){
      sum=0;
      for (k=0;k<D;++k){
        sum+=pow((double)a[i][k]-(double)a[j][k],2.0);
      }
      sum=sqrt(sum);
      if(sum==(double)(int)sum){
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>

#define M 1046527

using namespace std;


char table[M][13];


int h1(int key)
{
    return key % M;
}


int h2(int key)
{
    return 1 + (key % (M - 1));
}


int h(int key, int i)
{
    return (h1(key) + (i * h2(key))) % M;
}


int str_to_int(char T[])
{
    int len = strlen(T);
    int ret = 0;
    int pow = 1;
    for (int i = 0; i < len; i++) {
        ret += (T[i] - 'A') * pow;
        pow *= 4;
    }

    return ret;
}


void insert(char T[])
{
    int k = str_to_int(T);
    int i = 1;
    int hash = h(k, i);
    while (table[hash][0] != '\0') {
        hash = h(k, ++i);
    }
    strcpy(table[hash], T);
}


bool find(char T[])
{
    int k = str_to_int(T);
    int i = 1;
    int hash = h(k, i);
    while (table[hash][0] != '\0') {
        if (strcmp(table[hash], T) == 0)
            return true;
        hash = h(k, ++i);
    }
    return false;
}


void init(void)
{
    memset(table, 0, sizeof(table));
}


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

    char cmd[7];
    char str[13];

    for (int i = 0; i < n; i++) {
        cin >> cmd;
        cin >> str;

        if (cmd[0] == 'i') {
            insert(str);
        } else {
            if (find(str))
                cout << "yes" << endl;
            else
                cout << "no" << endl;
        }
    }
}



Measured memory_bytes: 16376
from collections import deque
N = int(input())
A0 = map(int, input().split(' '))
A1 = map(int, input().split(' '))
A = [list(A0), list(A1)]

visit = [[0 for _ in range(N)] for _ in range(2)]
visit[0][0] = 1
dp = [[0 for _ in range(N)] for _ in range(2)]
dp[0][0] = A[0][0]

Q = deque([(1, 0),])
if N > 1:
    Q.append((0, 1))
while len(Q) > 0:
    i, j = Q.popleft()

    if visit[i][j] == 1:
        continue
    dp[i][j] = A[i][j] + max(dp[max(0, i - 1)][j], dp[i][max(0, j - 1)])
    visit[i][j] = 1

    if i == 0 and j < N - 1:
        Q.append((i + 1, j))
        Q.append((i, j + 1))
    elif j < N - 1:
        Q.append((i, j + 1))

print(dp[1][-1])


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

int main(){
  int N;
  cin >> N;
  vector<long> H(N);
  for(int i=0; i<N; i++){
    cin >> H.at(i);
  }
  
  int ans=0,j=0,i=1;
  for(; i<N; i++){
    if(H.at(i-1)<H.at(i)){
      ans=max(ans,i-1-j);
      j=i;
    }
  }
  ans=max(ans,N-1-j);
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
template<class T> void chmin(T& x, T y){if(x < y) x = y;}
template<class T> void chmax(T& x, T y){if(x > y) x = y;}
int N ,X;
int D = 0;
int ans = 1;
int L[110];

int main(){
    cin >> N >> X;
    for(int i = 1; i <= N; i++){
        cin >> L[i];
        D += L[i];
        if(D <= X) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import qualified Data.Set as Set
import Data.List

g::Int->Int->Int->Int->Int->Int->[Int]->[Int]->[Int]->Set.Set (Int,Int,Int,Int,Int)->[Int]
g k 1 c2 x1 y1 z1 xs ys zs ss
          |x1-1>=0=let t=((xs!!(x1-1))+(ys!!y1)+zs!!(z1),1,x1-1,y1,z1)
                   in g k 2 c2 x1 y1 z1 xs ys zs (Set.insert t ss)
          |otherwise=g k 2 c2 x1 y1 z1 xs ys zs ss
g k 2 c2 x1 y1 z1 xs ys zs ss
          |y1-1>=0&&2<=c2=let t=((xs!!(x1))+(ys!!(y1-1))+zs!!z1,2,x1,y1-1,z1)
                          in g k 3 c2 x1 y1 z1 xs ys zs (Set.insert t ss)
          |otherwise=g k 3 c2 x1 y1 z1 xs ys zs ss
g k 3 c2 x1 y1 z1 xs ys zs ss
          |z1-1>=0&&3<=c2=let t=((xs!!(x1))+(ys!!(y1))+zs!!(z1-1),3,x1,y1,z1-1)
                          in f k xs ys zs (Set.insert t ss)
          |otherwise=f k xs ys zs ss


f::Int->[Int]->[Int]->[Int]->Set.Set (Int,Int,Int,Int,Int)->[Int]
f 1 _ _ _ ss=let (n,_,_,_,_)=Set.findMax ss
             in [n]
f k xs ys zs ss=let (n,c2,x1,y1,z1)=Set.findMax ss
                in n:(g (k-1) 1 c2 x1 y1 z1 xs ys zs (Set.deleteMax ss))
       

main = do
       ls<-getLine
       xs<-getLine
       ys<-getLine
       zs<-getLine
       let (x:y:z:k:[])=map read (words ls)::[Int]
           xs2=sort $ map read (words xs)::[Int]
           ys2=sort $ map read (words ys)::[Int]
           zs2=sort $ map read (words zs)::[Int]
           ts=(xs2!!(x-1)+ys2!!(y-1)+zs2!!(z-1),3,x-1,y-1,z-1)
       mapM_ putStrLn $ map show $ f k xs2 ys2 zs2 (Set.fromList [ts])

Measured memory_bytes: 2684
import Control.Applicative
import Control.Monad
import Data.List
data Count = In Int | Out Int deriving (Show)

countNum (In n) = n
countNum (Out n) = n

instance Eq Count where
    a == b = countNum a == countNum b
instance Ord Count where
    compare (In a) (Out b) = case compare a b of
                               EQ -> GT
                               _  -> compare a b
    compare (Out a) (In b) = case compare a b of
                               EQ -> LT
                               _  -> compare a b
    compare  a b = compare (countNum a) (countNum b)

main = do
    [n,t] <- map read.words<$>getLine
    customers <- replicateM n ((\[l,t] -> [In l, Out t]).map read.words<$>getLine)
    print $ maximum.cumSum.sort.concat$customers

cumSum :: [Count] -> [Int]
cumSum = scanl (\acc c -> case c of
                             (In _) -> acc+1
                             (Out _) -> acc-1) 0



Measured memory_bytes: 83936
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<tgmath.h>
using namespace std;

#define lld long long

int main(){
    int X,Y,A,B,C;
    vector<lld> p;
    vector<lld> q;
    vector<lld> r;
    cin >> X >> Y >> A >> B >> C;
    lld input;
    for(int i=0;i<A;i++){
        cin >> input;
        p.push_back(input);
    }
    for(int i=0;i<B;i++){
        cin >> input;
        q.push_back(input);
    }
    for(int i=0;i<C;i++){
        cin >> input;
        r.push_back(input);
    }
    sort(p.begin(),p.end());
    sort(q.begin(),q.end());
    sort(r.begin(),r.end());
    vector<lld> cmp;
    lld ans = 0;
    for(int i=0;i<X;i++){
        cmp.push_back(p.back());
        p.pop_back();
    }
    for(int i=0;i<Y;i++){
        cmp.push_back(q.back());
        q.pop_back();
    }
    for(int i=0;i<min(C,X+Y);i++){
        cmp.push_back(r.back());
        r.pop_back();
    }
    sort(cmp.begin(),cmp.end());
    for(int i=0;i<X+Y;i++){
        ans += cmp.back();
        cmp.pop_back();
    }
    cout << ans << endl;
}


Measured memory_bytes: 8560
MOD = 1000000007
H, W, A, B = map(int, input().split())
if H - A > W - B:
    H, W = W, H
    A, B = B, A
#print(H, W, A, B)
ans1 = [1]
for i in range(H - A - 1):
    #print(ans1)
    ans1.append((ans1[-1] * (H - A - 1 + B - i) * pow(i + 1, MOD - 2, MOD)) % MOD)
#print(ans1)
c = 1
for i in range(W - H + A - B):
    c = (c * (W - B - 1 + A - i) * pow(i + 1, MOD - 2, MOD)) % MOD
ans = c
for i in range(H - A - 1):
    #print(ans)
    c = (c * (H - 1 - i) * pow(W - H + A - B + 1 + i, MOD - 2, MOD)) % MOD
    ans = (ans + c * ans1[i + 1]) % MOD
print(ans)

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef double db; 
typedef string str;
 
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
 
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define endl '\n'
 
const ll MOD = 1000000007;

int main() {
   string s; cin >> s;
   int check = 0;
   for (char i : s)
      check += i - '0';
   if (check % 9 == 0) {
      printf("Yes");
   } else {
      printf("No");
   }
   return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

int a[555][555];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int H,W,h,w;
	cin>>H>>W>>h>>w;
	ll s=0;
	int x=4000;
	int y=x*(w*h-1)+1;
	for (int i=0;i<H;i++){
		for (int ii=0;ii<W;ii++){
			if (i%h==h-1&&ii%w==w-1){
				a[i][ii]=-y;
				s-=(ll)y;
			}
			else{
				a[i][ii]=x;
				s+=(ll)x;
			}
		}
	}
	if (s<=0){
		cout<<"No"<<endl;
		return 0;
	}
	else{
		cout<<"Yes"<<endl;
		for (int i=0;i<H;i++){
			for (int ii=0;ii<W;ii++){
				cout<<a[i][ii]<<" ";
			}
			cout<<endl;
		}
	}
}

Measured memory_bytes: 2688
N = int(input())
dic = {}
for i in range(N):
  s = input()
  if s not in dic:
    dic[s] = 1
  else:
    dic[s] += 1
  
M = int(input())
for i in range(M):
  t = input()
  if t not in dic:
    dic[t] = -1
  else:
    dic[t] -= 1

print(max(0,max(dic.values())))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

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

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	String s = sc.nextLine();
    	sc.close();
    	int ans = 753;
    	for(int i = 0; i < s.length()-2; i++){
    		int num = Integer.parseInt(s.substring(i, i+3));
    		ans = Math.min(ans, Math.abs(num - 753));
    	}
    	System.out.println(ans);
    }
}


Measured memory_bytes: 21844
//aea ctmr


#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

long long xd[200500];
long long aea[2300];

int main(){

	string s;
	cin >> s;

	long long n = s.size();
	long long curr = 0;
	long long wea = 1;
	for(long long i = n - 1; i >= 0; i--){
		curr += (s[i] - '0') * wea;
		wea *= 10;
		wea %= 2019;

		curr %= 2019;
		if(curr < 0) curr += 2019;
		//cout << curr << endl;
		aea[curr]++;

	}
	long long ans = 0;
	for(long long i = 1; i < 2300; i++){
		//if(aea[i] != 0) cout << aea[i] << endl;
		ans += ((aea[i] * aea[i] - aea[i]) / 2);
	}
	ans += (aea[0] * aea[0] + aea[0]) / 2;

	cout << ans << endl;


}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a < 6) {
        b = 0;
        cout << b << endl;
    }
    else if (a >= 6 && a <= 12) {
        b = b / 2;
        cout << b << endl;
    }
    else {
        cout << b;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

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

    int res = 0;
    for(int i=0;i<N;i++){
        while(h[i]>0){
            int k;
            for(k=i+1; k<N; k++){
                if(h[k]==0){
                    break;
                }
            }
            for(int j=0;j<k;j++){
                h[j]--;
            }
            res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
    int n,m;
    int a[200000],b[200000];
    int land1[200000]={0};
    int land2[200000]={0};

    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d %d",&a[i],&b[i]);
        if(a[i]==1&&b[i]==n){
            printf("IMPOSSIBLE\n");
            return 0;
        }
        if(b[i]==n){
            land2[a[i]-1]++;
        }
        if(a[i]==1){
            land1[b[i]-1]++;
        }
    }
    for(int i=0;i<n;i++){
        if(land1[i]>=1&&land2[i]>=1){
            printf("POSSIBLE\n");
            return 0;
        }
        //printf(">%d %d %d\n",i,land1[i],land2[i]);
    }
    printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
const int N=1e7;
int fact[N+5],inv[N+5],Inv[N+5];
int power(int x,int y){
	int ret=1;
	do{
		if(y&1)ret=(ll)ret*x%mod;
		x=(ll)x*x%mod;
	}while(y>>=1);
	return ret;
}
int n,A;
inline void add(int &x,int y){
	x+=y;if(x>=mod)x-=mod;
}
inline void sub(int &x,int y){
	x-=y;if(x<0)x+=mod;
}
inline int comb(int nn,int mm){
	return (ll)fact[nn]*inv[mm]%mod*inv[nn-mm]%mod;
}
int main(){
	fact[0]=1;for(int i=1;i<=N;i++)fact[i]=(ll)fact[i-1]*i%mod;
	inv[N]=power(fact[N],mod-2);for(int i=N-1;i>=0;i--)inv[i]=(ll)inv[i+1]*(i+1)%mod;
	for(int i=1;i<=N;i++)Inv[i]=(ll)fact[i-1]*inv[i]%mod;
	cin>>n>>A;
	int ans=0;
	for(int t=2;t<=A+1;t++){
		int a=t-1,b=max(0,A-t),c=n-A;
		for(int d=0;d<=a;d++){
			if(d&1)sub(ans,(ll)comb(a,d)*fact[a+b+c-d]%mod*(a-d)%mod*Inv[a-d+c]%mod);
			else add(ans,(ll)comb(a,d)*fact[a+b+c-d]%mod*(a-d)%mod*Inv[a-d+c]%mod);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 120796
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long ans = 1L;
		for(int i = 0; i < n; i++) {
			ans = lcm(ans, sc.nextLong());//答えと入力の最小公倍数
		}
		System.out.println(ans);
	}
	static long lcm(long a, long b) {//最小公倍数
		long g = gcd(a, b);
		return a / g * b;//ユークリッドの互除法により
		// a*b = (aとbの最小公倍数) * (aとbの最大公約数)
		//式変形して	a / (aとbの最大公約数) * b = (aとbの最小公倍数)
		//これで最小公倍数が求まる
	}
	static long gcd(long a, long b) {//最大公約数
		if(b == 0) return a;
		return gcd(b, a%b);
	}
}

Measured memory_bytes: 23636
#include<cstdio>
#include<vector>
typedef std::pair<std::vector<int>,std::vector<int> > stacks;
stacks trans(stacks ss,int i,int K,bool&fl){
	std::vector<int>s1,s2;
	for(int j=ss.second.size();j--&&fl;)if(ss.second[j]==i)return fl=0,std::make_pair(s1,s2);
	int j=0;while(j<ss.first.size()&&ss.first[j]!=i)j++;
	if(j==ss.first.size()&&ss.first.size()+ss.second.size()+1==K||!j&&ss.first.size()==K){
		for(j==ss.first.size()?j=0:++j;j<ss.first.size();j++)s1.push_back(ss.first[j]);
		for(j=0;j<ss.second.size();j++)s1.push_back(ss.second[j]);
		s1.push_back(i);
	}
	else{
		for(j==ss.first.size()?j=0:++j;j<ss.first.size();j++)s1.push_back(ss.first[j]);
		s2=ss.second;s2.push_back(i);
	}
	return std::make_pair(s1,s2);
}
bool chk(std::pair<stacks,std::vector<int> >st){
	stacks ss=st.first;
	std::vector<int>c=st.second;
	int N=0,K=c.size();
	for(int i=ss.second.size();i--;)c[ss.second[i]]++;
	for(int i=0;i<K;i++)N+=c[i];
	if(!N)return!ss.second.size();
	int ty[K],M=0;
	for(int i=0;i<K;i++)ty[i]=0,c[i]>M?M=c[i]:1;
	for(int i=0;i<ss.first.size();i++)ty[ss.first[i]]=1;
	for(int i=0;i<ss.second.size();i++)ty[ss.second[i]]=2;
	bool fl=1;
	int p=ss.first.size(),q=ss.second.size();
	while(p&&c[ss.first[p-1]]<M)--p;
	for(int i=0;i<K;i++)if(!ty[i])ty[i]=c[i]==M?fl=0,3:2;
	for(int i=0;i<p;i++)ty[ss.first[i]]=c[ss.first[i]]==M?fl=0,3:2;
	if(fl)while(q&&c[ss.second[q-1]]<M)--q;
	else fl=1;
	for(int i=0;i<q;i++)ty[ss.second[i]]=3;
	for(int i=0;i<K&&fl;i++)if(c[i]<M){
		if(ty[i]+(M-c[i]-1)*2>M)fl=0;
	}
	return fl;
}
int main(){
	int K;
	while(scanf("%d",&K)==1){
		int N=0;
		stacks ss;
		std::vector<int>c;
		for(int i=0,x;i<K;i++)scanf("%d",&x),c.push_back(x),N+=x;
		if(!chk(std::make_pair(ss,c)))puts("-1");
		else while(N--){
			bool fl=0;
			for(int i=0;i<K&&!fl;i++)if(c[i]){
				c[i]--;fl=1;
				stacks ns=trans(ss,i,K,fl);
				if(fl&&chk(std::make_pair(ns,c)))ss=ns,printf("%d%c",i+1," \n"[!N]);
				else fl=0,c[i]++;
			}
		}
	}
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    char n;
    cin >> n;
    if(n=='a'||n=='e'||n=='i'||n=='o'||n=='u'){
        cout<<"vowel"<<endl;
    }else{
        cout<<"consonant"<<endl;
    }
    return 0;
}

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

ll mpower(ll a,ll b,ll c){
  int z;
  if(b==0){
    z=1;
    z%=c;
    return z;
  }
  if(b==1){
    z=a;
    z%=c;
    return z;
  }
  else{
    return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
  }
}

const int MAX = 2100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

// 二項係数計算
long long COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  COMinit();
  ll mod=1e9+7;
  int k;
  string S;
  cin>>k>>S;
  int s=S.size();
  ll ans=mpower(26,s+k,mod);
  ll ansb=0;
  for(ll i=0;i<s;i++){
    ansb+=mpower(25,s+k-i,mod)*COM(s+k,i);
    ansb%=mod;
  }
  ans-=ansb;
  while(ans<0){
    ans+=mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 54552
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
		int anser = 0;
		int[] count = new int[5];
		for(int i = 0;i < 5;i++) {
			int x = sc.nextInt();
			count[i] += x;
			if(count[i] == 0) {
				anser = i;
			}
		}
		System.out.println(anser + 1);
  }
}

Measured memory_bytes: 35700
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
ans = [0] * n
for i, c in enumerate(t):
    if i >= k and c == t[i - k] and ans[i - k] > 0:
        continue
    if c == 'r':
        ans[i] = p
    elif c == 's':
        ans[i] = r
    else:
        ans[i] = s
print(sum(ans))


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int w,h,x,y,r; cin>>w>>h>>x>>y>>r;
	cout<<(x-r<0||x+r>w||y-r<0||y+r>h?"No"s:"Yes"s)<<"\n"s;
}


Measured memory_bytes: 3228
print([list(it.takewhile(lambda x: any([globals()['s'].endswith(w) and (globals().__setitem__('s', globals()['s'][:-len(w)]) or True) or False for w in ["dreamer", "eraser", "dream", "erase"]]), it.repeat([]))) for it in [__import__("itertools")] for _ in [globals().__setitem__('s', input())]] and len(globals()['s']) == 0 and "YES" or "NO")

Measured memory_bytes: 3340
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
#include <cmath>

using namespace std;

#define F first
#define S second

#define X real()
#define Y imag()

#define EPS (1e-7)

typedef complex<double> Point;
typedef vector<Point> Polygon;
typedef pair<double, Point> Circle;

bool isPointInCircle(const Point& p, const Circle& c) {
  if(abs(p-c.S) < abs(c.F) + EPS) return true;
  return false;
}

double dot(const Point& a, const Point& b) {
  return a.X*b.X+a.Y*b.Y;
}

double cross(const Point& a, const Point& b) {
  return a.X*b.Y-a.Y*b.X;
}

typedef pair<Point, Point> Segment;
typedef Segment Line;

double distanceLP(Line l, Point p) {
  return abs(cross(l.S-l.F, p-l.F)) / abs(l.S-l.F);
}

double distanceSP(Segment s, Point p) {
  Point a = s.F, b = s.S;
  
  if(dot(b-a, p-a) < EPS) return abs(p-a);
  if(dot(a-b, p-b) < EPS) return abs(p-b);
  return distanceLP(s, p);
}


enum struct ECont { OUT, ON, IN };
ECont contains(const Polygon& poly, const Point& p) {
  bool in = 0;
  for(int i=0; i<poly.size(); i++) {
    Point a = poly[i] - p, b = poly[(i+1)%poly.size()] - p;
    if(a.imag() > b.imag()) swap(a, b);
    if(a.imag() <= 0 && 0 < b.imag()) {
      if(cross(a, b) < 0) in = !in;
    }
    if(cross(a, b) == 0 && dot(a, b) <= 0) return ECont::ON;
  }
  
  return in ? ECont::IN : ECont::OUT;
}

int main() {
  
  while(1) {
    Polygon points(3);
    Circle circle;
  
    for(int i=0; i<3; i++) {
      double x, y; cin >> x >> y;
      if(x == 0) return 0;
    
      points[i] = Point(x, y);
    }
  
    {
      double x, y; cin >> x >> y;
      circle.S = Point(x, y);
      cin >> circle.F;
    }
  
    bool ok = 1;
    for(int i=0; i<3; i++) {
      ok &= isPointInCircle(points[i], circle);
    }
    if(ok) {
      cout << 'b' << endl;
      continue;
    }
    
    int uncross = 0;
    for(int i=0; i<3; i++) {
      Segment seg = make_pair(points[(i+1)%3], points[i]);
      uncross += circle.F < distanceSP(seg, circle.S) + EPS;
    }
    if(uncross == 3) {
      int flg = 0;
      for(int i=0; i<3; i++) {
        if(contains(points, circle.S) == ECont::IN) {
        //if(dot(points[(i+1)%3]-points[i], circle.S-points[i]) * dot(points[(i+2)%3]-points[(i+1)%3], circle.S-points[(i+1)%3]) > 0) {
          flg ++;
        }
      }
      if(flg == 3) { cout << 'a' << endl; continue; }
    }

    int cross = 0;
    for(int i=0; i<3; i++) {
      Segment seg = make_pair(points[(i+1)%3], points[i]);
      cross += distanceSP(seg, circle.S) <= circle.F + EPS;
    }
    if(cross > 0) cout << 'c' << endl;
    else cout << 'd' << endl;
  }
  
  return 0;
}

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
const int MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
struct edge { int i, v; };

void dfs(int u, vector<vector<int> >& G, vector<int>& a, vector<int>& b) {
	int M = a[u];
	vector<int> dp(M + 1, INF);
	dp[0] = 0;
	for (int v: G[u]) {
		dfs(v, G, a, b);
		vector<int> _dp(M + 1, INF);
		for (int x = 0; x + a[v] <= M; x++)
			_dp[x + a[v]] = min(_dp[x + a[v]], dp[x] + b[v]);
		for (int x = 0; x + b[v] <= M; x++)
			_dp[x + b[v]] = min(_dp[x + b[v]], dp[x] + a[v]);
		dp = _dp;
	}
	b[u] = INF;
	rep(x, M + 1) b[u] = min(b[u], dp[x]);
}

int main() {
	int N; cin >> N;
	vector<vector<int> > G(N);
	for (int u = 1; u < N; u++) {
		int p; cin >> p; p--;
		G[p].pb(u);
	}
	vector<int> a(N);
	rep(u, N) cin >> a[u];
	vector<int> b(N);
	dfs(0, G, a, b);
	cout << (b[0] < INF ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 5756
#include<bits/stdc++.h>
using namespace std;
int x,m=1,tag;
bool table[1005];
int pow(int x, int t)
{
    int ans=x;
    t--;
    while(t)
	{
        ans*=x;
        t--;
    }
    return ans;
}
int main(){
    table[1]=1;
    for(int i=2;i<=1000;i++){
        int t=2;
        while((int)pow(i,t)<=1000)
		{
            table[pow(i,t)]=1;
            t++;
        }
    }
    cin>>x;
    for(int i=x;i>=1;i--)
	{
        if(table[i])
		{
            cout<<i;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 2e6 + 10;
const ll mod = 1e9 + 7;
int n, m, k;
ll a[3010][3010];
ll dp[3010][3010][4];
int main() {
	scanf("%d%d%d", &n, &m, &k);
	//for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)a[i][j] = -inf;
	for (int i = 1; i <= k; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		scanf("%lld", &a[x][y]);
	}
	//for (int i = 0; i <= n; i++)for (int j = 0; j <= m; j++)for (int x = 0; x <= 3; x++)dp[i][j][k] = -inf;
	for (int i = 0; i <= n; i++)for (int j = 0; j <= m; j++)dp[i][j][0] = 0;
	dp[1][1][0] = 0; if (a[1][1] >= 0)dp[1][1][1] = a[1][1];
	ll ans = a[1][1];
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			//if (i == 1 && j == 1)continue;
			for (int k = 1; k <= 3; k++) {
				dp[i][j][k] = max(dp[i - 1][j][3] + a[i][j], max(dp[i][j - 1][k - 1] + a[i][j], dp[i][j - 1][k]));
				ans = max(ans, dp[i][j][k]);
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 356536
n, m = map(int, input().split())
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
ab.sort()
c = 0
for i in range(n):
    if m < 1:
        break;
    c += ab[i][0]*min(m, ab[i][1])
    m -= ab[i][1]
print(c)

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> a(h+2, vector<char>(w+2));
  for (int i = 0; i < h+2; i++){
    for (int j = 0; j < w+2; j++){
      if ((i == 0) || (i == h+1)) {
        a.at(i).at(j) = '#';
        continue;
      }
      if ((j == 0) || (j == w+1)) {
        a.at(i).at(j) = '#';
        continue;
      }
      cin >> a.at(i).at(j);
    }
  }
  
  for (int i = 0; i < h+2; i++){
    for (int j = 0; j < w+2; j++){
      cout << a.at(i).at(j);
    }
    cout << endl;
  }
}





Measured memory_bytes: 256
S = input()

ans = 0
for i in range(len(S)):
    for j in range(i, len(S)):
        ok = True
        for k in range(i, j+1):
            if not (S[k] == "A" or S[k] == "C" or S[k] == "G" or S[k] == "T"):
                ok = False
                break
        if ok:
            ans = max(ans, j - i + 1)

print(ans)


Measured memory_bytes: 61968
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
using namespace std;
int c[3000010];
int main(){
	int N,M;
	while(cin>>N>>M&&N){
		int h[1503],w[1503];
		int ans=0;
		REP(i,0,3000010) c[i]=0;
		h[0]=w[0]=0;
		REP(i,1,N+1) {
			cin>>h[i];
			h[i]+=h[i-1];
		}
		REP(i,1,M+1){
			cin>>w[i];
			w[i]+=w[i-1];
		}
		REP(i,0,N+1) REP(j,0,M+1) c[h[i]-w[j]+1500000]++;
		REP(i,0,3000010) 	ans+=c[i]*(c[i]-1)/2;
		p(ans);
	}
	return 0;
}

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

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



Measured memory_bytes: 3120
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const MOD: i64 = 1_000_000_007;

fn main() {
    let mut n: i64 = read();
    let mut m: i64 = read();
    if (n - m).abs() > 1 {
        println!("0");
        return;
    }

    let mut a: i64 = 1;
    let mut b: i64 = 1;
    while n > 0 {
        a *= n;
        a %= MOD;
        n -= 1;
    }
    while m > 0 {
        b *= m;
        b %= MOD;
        m -= 1;
    }

    if a == b {
        let tmp = a * b % MOD;
        println!("{}", tmp * 2 % MOD);
    } else {
        let tmp = a * b % MOD;
        println!("{}", tmp);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

template
<   
    typename TYPE,
    std::size_t SIZE
>
std::size_t array_length(const TYPE (&)[SIZE])
{   
    return SIZE;
}


vector<int> enum_div(int n){
    vector<int> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

int main(void){
    int n;
    cin >> n;
    int r = 0;
    vector<int> p(1);

    for (int i=1; i <= n; i += 2) {
        p = enum_div(i);
        if (p.size() + 1 == 8) r++;
    }
    

    

    
    cout << r;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
void solution(int b, int c)
{
	int base=c-1;
	int exp=b-1;
	int r=pow(base,exp);
	cout<<r*c<<endl;
}
main()
{
	int b,c;
	cin>>b;
	cin>>c;
	solution(b,c);
}






Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int A, B, C, X;

int main() {
  cin >> A >> B >> C >> X;
  int ans = 0;
  repe(i, 0, A) {
    repe(j, 0, B) {
      repe(k, 0, C) {
        int total = 500 * i + 100 * j + 50 * k;
        if (total == X) {
          ++ans;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    s = str(input())
    q = inp()
    before = []
    after = []
    flag = True
    for _ in range(q):
        query = inpls()
        if query[0] == '1':
            if flag:
                flag = False
            else:
                flag = True
        else:
            f = query[1]
            S = query[2]
            if (flag and f=='2') or ((not flag) and f=='1'):
                after.append(S)
            else:
                before.append(S)
    ans = []
    for i in range(len(before)-1,-1,-1):
        ans.append(before[i])
    s = list(s)
    for i in range(len(s)):
        ans.append(s[i])
    for i in range(len(after)):
        ans.append(after[i])
    if not flag:
        ans.reverse()
    print(''.join(ans))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 94420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e3 + 7;
const int MOD = 1e9 + 7;

int dp[N][N][2];

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i=0; i<=n; i++)
		dp[0][i][1] = 1;
	for (int i=1; i<=m; i++)
	{
		for (int j=0; j<=n; j++)
		{
			if (j == 0)
			{
				dp[i][j][1] = dp[i][j][0] = (dp[i-1][j][1] + dp[i-1][j+1][1]) % MOD;
			}
			else if (j == n)
			{
				dp[i][j][1] = dp[i][j][0] = (dp[i-1][j][1] + dp[i-1][j-1][1]) % MOD;
			}
			else
				for (int k=0; k<2; k++)
					dp[i][j][k] = (dp[i-1][j][k] * 2LL + 1LL * dp[i-1][j-1][k] + 1LL * dp[i-1][j+1][k]) % MOD;
		}
	}
	int ans = 0;
	for (int i=0; i<=n; i++)
		ans = (ans + dp[m][i][0]) % MOD;
	cout << ans << "\n";
}

Measured memory_bytes: 70784
#include <stdio.h>
#include <string.h>

int main()
{
  int o, i, j, k;
  
  int alen, blen;
  
  char a[1000],b[1000];
  
  int c[1001][1001];
  
  scanf("%d\n",&o);

  
  for (k=0;k<o;k++) {
    
    scanf("%s",a);
    alen = strlen(a);
    
    if (a[alen-1]=='\n'){
      a[alen-- -1]='\0';
    }
    scanf("%s",b); 
    blen = strlen(b);
    
    if (b[blen-1]=='\n'){
      
      b[(blen--)-1]='\0';
      
    }
    
    c[0][0]=0;
    
    for (i=0; i<alen; i++){
      
      for (j=0; j<blen; j++){
	
        if (a[i]==b[j]){
	  
          c[i+1][j+1] = c[i][j]+1;
	  
	}
	
        else
	  {
	    if(c[i][j+1] > c[i+1][j])  c[i+1][j+1] = c[i][j+1];
	    else c[i+1][j+1] = c[i+1][j];
	   
	  }
      }
    }
    
    printf("%d\n",c[alen][blen]);
    
  }
  return 0;
}



Measured memory_bytes: 5664
#include<stdio.h> 
#include<stdlib.h> 
#include<string.h>  
int main(void){
char num_str[1002];
int num;
long long int sum =0;
int i;
char tmp;     
while(1){    
fgets(num_str,1002,stdin);    
if(num_str[0]=='0') break;    
for(i=0;i<strlen(num_str)-1;i++){        
tmp = num_str[i];        
num = atoi(&tmp);        
sum = sum + num;    }     
printf("%lld\n",sum);    
sum = 0;    
memset(num_str,1002,0);}
return 0;
}

Measured memory_bytes: 532
#include<iostream>
using namespace std;
int x[1000], y[1000];
int main() {
	int n, sum; cin >> n;
	for (int i = 0; i < n; i++)cin >> x[i] >> y[i];
	for (int i = 0; i < n; i++) { sum += (x[i] - x[(i + 1) % n])*(y[i] + y[(i + 1) % n]); }
	cout << sum / 2 << '.' << (sum % 2) * 5 << endl;
	return 0;
}

Measured memory_bytes: 1172
#include <stdio.h>

int main () {
	int A, B, C;
	scanf ("%d %d", &A, &B);
	C = A + B;
	
	if (A > 8 or B > 8) {
	printf (":(");}
	else if (C > 18) {
	printf (":(");}
	else {
	printf ("Yay!");}
	return 0;
}

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

const int MAXN = 1e5 + 10;
const int INF = 2*1e9;

int dp[MAXN],N,K,h[MAXN];

int main(){

	scanf("%d %d",&N,&K);
	for(int i = 1;i<=N;i++){
		scanf("%d",&h[i]);
	}

	for(int i = 2;i<=N;i++){
		dp[i] = INF;
		for(int j = i-1;j>=max(i - K,1);j--){
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]) );
		}
	}

	printf("%d\n",dp[N]);

	return 0;

}

Measured memory_bytes: 4600
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int pay = 0;
        while(pay < n){
            pay += 1000;
        }
        System.out.println(pay - n);
        scan.close();
    }
}


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

using namespace std;

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

    int a, b;
    char op;

    cin >> a >> op >> b;
    if (op == '+')
        cout << a + b << endl;
    else
        cout << a - b << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

ll modpow(ll b, ll n)
{
  ll ret = 1;
  for (int i = n; i > 0; i >>= 1) {
    if (i & 1) { ret = (ret * b) % MOD; }
    b = (b * b) % MOD;
  }
  return ret;
}

ll combi(int n, int r, vector<ll>& fact, vector<ll>& inv_fact)
{
  if (r > n) { return 0; }
  ll ret = (fact[n] * inv_fact[r]) % MOD;
  return (ret * inv_fact[n - r]) % MOD;
}

int main()
{

  ll H, W, A, B; scanf("%lld %lld %lld %lld", &H, &W, &A, &B);
  ll N = H + W;
  vector<ll> fact(N + 5, 1), inv_fact(N + 5, 1);
  for (int i = 1; i <= N; ++i) {
    fact[i] = (i * fact[i - 1]) % MOD;
  }
  inv_fact[N] = modpow(fact[N], MOD - 2);
  for (int i = N; i > 0; --i) {
    inv_fact[i - 1] = (i * inv_fact[i]) % MOD;
  }

  ll ans = 0;
  for (int i = B + 1; i <= W; ++i) {
    ll n = i - 1 + H - A - 1;
    ll r = i - 1;
    ll val = combi(n, r, fact, inv_fact);
    n = A - 1 + W - i;
    r = A - 1;
    val = (val * combi(n, r, fact, inv_fact)) % MOD;
    ans = (ans + val) % MOD;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3328