akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

template<int mod>
struct Modint{
    int x;
    Modint():x(0){}
    Modint(int64_t y):x((y%mod+mod)%mod){}

    Modint &operator+=(const Modint &p){
			if((x+=p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator-=(const Modint &p){
			if((x+=mod-p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator*=(const Modint &p){
			x = (1LL * x * p.x) % mod;
			return *this;
		}

		Modint &operator/=(const Modint &p){
			*this *= p.inverse();
			return *this;
		}

		Modint operator-() const { return Modint(-x); }
		Modint operator+(const Modint &p) const{
			return Modint(*this) += p;
		}
		Modint operator-(const Modint &p) const{
			return Modint(*this) -= p;
		}
		Modint operator*(const Modint &p) const{
			return Modint(*this) *= p;
		}
		Modint operator/(const Modint &p) const{
			return Modint(*this) /= p;
		}

		bool operator==(const Modint &p) const { return x == p.x; }
		bool operator!=(const Modint &p) const{return x != p.x;}

		Modint inverse() const{//非再帰拡張ユークリッド
			int a = x, b = mod, u = 1, v = 0;
			while(b>0){
				int t = a / b;
				swap(a -= t * b, b);
				swap(u -= t * v, v);
			}
			return Modint(u);
		}

		Modint pow(int64_t n) const{//繰り返し二乗法
			Modint ret(1), mul(x);
			while(n>0){
				if(n&1)
					ret *= mul;
				mul *= mul;
				n >>= 1;
			}
			return ret;
		}

		friend ostream &operator<<(ostream &os,const Modint &p){
			return os << p.x;
		}
};

using modint = Modint<mod>;


void solve()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	const ll m=998244353;
	vector<vector<Modint<m>>>dp(c+5,vector<Modint<m>>(d+5));
	dp[a][b]=1;
	REP(i,a,c+1){
		REP(j,b,d+1){
			if(i==c&&j==d)continue;
			dp[i+1][j]+=dp[i][j]*j;
			dp[i][j+1]+=dp[i][j]*i;
			dp[i+1][j+1]-=dp[i][j]*i*j;
		}
	}
	cout<<dp[c][d]<<"\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 38352
import sys

input = sys.stdin.readline


def main():
    s = int(input())
    ans = [0, 0]
    # bottom = 0
    # top = 10**9
    # while bottom < top:
    #     middle = (bottom+top)//2
    #     if middle*10**9 <= s:
    #         bottom = middle+1
    #     else:
    #         top = middle-1
    x1 = int(('0'*9+str(s))[:-9])+1
    x1 = x1-1 if x1 == 10**9+1 else x1

    # x1 = top if top >= bottom else bottom
    ans.append(x1)
    ans.append(1)
    ans.append(x1*10**9-s)
    ans.append(10**9)
    print(*ans)
    # print(abs(ans[2]*ans[5]-ans[3]*ans[4]))
    # print(s == abs(ans[2]*ans[5]-ans[3]*ans[4]))
    # print([0 <= i <= 10**9 for i in ans])
    # print(top, bottom)


if __name__ == "__main__":
    main()


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


int main() {
	
	int w, h;



	while (true) {
		cin >> h >> w;
		if (h == 0 && w == 0)break;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				printf("#");

			}
			printf("\n");
		}
		printf("\n");
	}


	//system("pause");
	return 0;
}


Measured memory_bytes: 3028
#include<iostream>
using namespace std;
int aaa(int x,int y)
{

	for(int a=0;a<1+y;a++)
	{
	for(int b=0;b<y+1;b++)
	{
		for(int c=0;c<y+1;c++)
		{
			for(int d=0;d<y+1;d++)
			{
				for(int e=0;e<y+1;e++)
				{
					for(int f=0;f<y+1;f++)
					{
					if(x==100*a+101*b+102*c+103*d+104*e+105*f)
				{return 1;
				}
				}
				}
				
			}
		}
		}	
	}
	return 0;	
}
int main()
{
	int x;
	cin>>x;
	int y=x/100;
	cout<<aaa(x,y);
}



Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
#define interest 1.05

int main()
{
	double thous = 100;
	int debt;
	int n;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		thous = ceil(thous * interest);
	}
	debt = thous * 1000;
	cout << debt << "\n";
	return 0;
}

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

int main(){
	
	int m ;
	int capital , year , n ;
	int s , t ;
	double r ;
	
	int max , keep , money ;
	
	cin >> m ;
	
	for( int i=0 ; i<m ; i++ ){
		cin >> capital >> year ;
		cin >> n ;
		max = 0 ;
		for( int j=0 ; j<n ; j++ ){
			cin >> s ;
			cin >> r >> t ;
			
			money = capital ;
			keep = 0 ;
			
			for( int k=0 ; k<year ; k++ ){
				if( s==1 ) money += money * r - t ;
				else {
					keep += money * r ;
					money -= t ;
				}
			}
			
			if( max < money + keep ) max = money + keep ;
		}
		
		cout << max << endl ;
	}
	
	
	
return 0;
}

Measured memory_bytes: 1232
using System;

class Program
{
    static void Main(string[] args)
    {
        int price = int.Parse(Console.ReadLine());
        int ans = 0;

        if (price == 0)
        {
            price = 1000;
        }

        if (price <= 1000)
        {
            ans = 1000 - price;
        }
        else
        {

            int amari = price % 1000;
            if (amari != 0)
            {
                ans = 1000 - amari;
            }
            else
            {
                ans = 0;
            }

        }

        Console.WriteLine(ans.ToString());
    }
}

Measured memory_bytes: 27476
prime_five = []
for i in range(3, 55555):
	j = 2
	while j ** 2 <= i:
		if i % j == 0:
			break
		j += 1
	else:
		if i % 5 == 1:
			prime_five.append(i)

n = int(input())
ans = []

for i in range(n):
	ans.append(str(prime_five[i]))

print(' '.join(ans))


Measured memory_bytes: 3060
//ABC130B
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main(){
	double W, H, x, y;
	double s;
	int num;
	scanf("%lf %lf %lf %lf",&W,&H,&x,&y);
	s = W*H/2.0;
	if(x==W/2.0 && y==H/2.0){
		num = 1;
	}else{
		num = 0;
	}
	printf("%lf %d",s,num);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define frst first
#define sec second
#define fast cin.tie(0) , ios_base :: sync_with_stdio(0)
#define db double
#define mod 1000000007
void online_judge()
{
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}


ll dp[200001];

ll dfs(vector<ll> g[] , ll strt , bool* vis)
{
	vis[strt] = 1;
	ll ans = 1;
	for (auto x : g[strt])
	{
		if (!vis[x]) {
			ans = max(ans , 1 + dfs(g , x , vis));
		}
		else {
			ans = max(ans , 1 + dp[x]);
		}
	}
	///cout << ans << " ";
	return dp[strt] = ans;
}

unordered_map<ll, db> u[3000];
db cal(db a[] , ll n , ll cur)
{
	if (n == 0) {
		if (cur > 0)return 1;
		return 0;
	}
	if (u[n].count(cur))return u[n][cur];
	db ans = 0;
	ans += (cal(a , n - 1, cur + 1) * a[n - 1] +  cal(a , n - 1 , cur - 1) * (1 - a[n - 1]));
	return u[n][cur] = ans;
}

void go() {
	ll n;
	cin >> n;
	db a[n];
	for (int i = 0 ; i < n; ++i)cin >> a[i];
	cout << fixed << setprecision(10) << cal(a , n , 0);
}


int main() {
	fast;
	//online_judge();
	//cout << 2332;
	go();
}

Measured memory_bytes: 194176
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <string>
using namespace std;

int main()
{   int N, L;
    vector<string> strings;
    string str;
    cin >> N >> L;
    for(int i = 0; i < N; i++){
        cin >> str;;
        strings.push_back(str);
    }
    sort(strings.begin(), strings.end());
    str = strings[0];
    if(N > 1){
        for(int i = 1; i < N; i++){
            str += strings[i];
        }
    }
    cout << str << endl;
    return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
int A[100100], B[100100];
ll res;

void f(int i, int j){
    int n = std::min(B[i], A[j]);

    res += n;

    B[i] -= n;
    A[j] -= n;
}

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

    std::cin >> N;

    for(int i=0;i<N+1;++i){
        std::cin >> A[i];
    }

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

    for(int i=0;i<N;++i){
        f(i, i);
        f(i, i + 1);
    }

    std::cout << res << std::endl;
}


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

int main()
{
  int A, B;
  char op;
  cin >> A >> op >> B;

  if (op == '+')
  {
    cout << A + B << endl;
  }
  else
  {
    cout << A - B << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;

  int res = 0;
  string tmp;
  for (int i=a; i<=b; i++) {
    tmp = to_string(i);
    switch (tmp.length()) {
      case 1:
        res++;
        break;
      case 2:
        if (tmp[0] == tmp[1]) res++;
        break;
      case 3:
        if (tmp[0] == tmp[2]) res++;
        break;
      case 4:
        if (tmp[0] == tmp[3] && tmp[1] == tmp[2]) res++;
        break;
      case 5:
        if (tmp[0] == tmp[4] && tmp[1] == tmp[3]) res++;
        break;
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int n, m;
vector<vector<int>> g;
vector<int> ans, len;
vector<bool> visited;

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

  cin >> n >> m;
  g.resize(n);
  visited.resize(n, false);
  len.resize(n, 1e9);
  ans.resize(n);
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (a > b)
      swap(a, b);
    g[a].push_back(b);
    if (a != 0)
      g[b].push_back(a);
    else {
      len[b] = 1;
      ans[b] = 1;
    }
  }

  queue<int> q;
  vector<int> shortest_route(n, 1e9);
  q.push(0);
  len[0] = 0;
  shortest_route[0] = 0;
  while (!q.empty()) {
    int z = q.front();
    q.pop();
    visited[z]=true;
    for (auto x : g[z]) {
      if(visited[x])continue;
      if (shortest_route[x] > shortest_route[z] + 1) {
        shortest_route[x] = shortest_route[z] + 1;
        ans[x]=z;
        q.push(x);
      }
    }
  }

  cout << "Yes" << endl;
  rep(i, 1, n) cout << ans[i] + 1 << endl;
}


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

int main() {
  int N,i,m=0;
  cin >> N;
  vector<int> A(N), B(N);

  cin >> A.at(0);
  for(i=1; i<N; i++) {
    cin >> A.at(i);
    A.at(i) += A.at(i-1);
  }
    
  for(i=0; i<N; i++)
    cin >> B.at(i);
  for(i=N-2; i>=0; i--)
    B.at(i) += B.at(i+1);

  for(i=0; i<N; i++)
    m = max(m, A.at(i)+B.at(i));
  cout << m << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;
 
vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
// priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
//ll mod = 998244353;
ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,h,r,l;
ll k;
ll ans;
ll x[500005], y[500005];
ll dp[20][20];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(ll i=1;i<=n;i++){
        ll front, last;
        last = i % 10;
        ll num = i;
        while(true){
            if(num <= 9){
                front = num;
                break;
            }else{
                num /= 10;
            }
        }
        dp[front][last] ++;
    }
    for(ll i=1;i<=n;i++){
        ll front, last;
        last = i % 10;
        ll num = i;
        while(true){
            if(num <= 9){
                front = num;
                break;
            }else{
                num /= 10;
            }
        }
        ans += dp[last][front];
    }
    p(ans);
    
    return 0;
}
 











Measured memory_bytes: 14848
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n = inp[0]
p kaijo(n)

Measured memory_bytes: 2300
import Control.Monad ( replicateM )
import Data.List ( sort, group )
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [n,m] <- readInts
  abs   <- replicateM m readInts
  mapM_ print $ honsu n abs

honsu
  :: Int -> [[Int]] -> [Int]
honsu n as = map length' . group . sort . concat $ ([1..n] : as)
  where
    length' l = length l - 1

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

using namespace std;

typedef long long int ll;

int main(){
    int h, w;
    cin>>h>>w;
    ll modulo = 1000000007;
    char maze[h][w];
    for(int i = 0;i< h;i++){
        for(int j =0;j< w;j++){
            cin>>maze[i][j];
        }
    }
    ll dp[h][w];
    memset(dp, 0, sizeof(dp));
    int flag = 0;
    for(int i = 1;i< h;i++){
        if(maze[i][0] == '#')break;
        dp[i][0] = 1;
    }
    for(int i = 0;i< w;i++){
        if(maze[0][i] == '#')break;
        dp[0][i] =1;
    }
    for(int i = 1;i< h;i++){
        for(int j = 1;j< w;j++){
            // if(i == 0 && j == 0)continue;
            if(i-1>=0 ){
                if(maze[i][j] == '.')dp[i][j] += (dp[i-1][j])%modulo;
            }
            if(j-1>= 0){
                if(maze[i][j] == '.')dp[i][j] += dp[i][j-1]%modulo;
            }
            dp[i][j] = dp[i][j] %modulo;
        }
    }
    // for(int i = 0;i< h;i++){
    //     for(int j = 0;j< w;j++){
    //         cout<<dp[i][j]<<' ';
    //     }
    //     cout<<endl;
    // }
    cout<<dp[h-1][w-1];
}

Measured memory_bytes: 9088
readint()=parse.(Int,readline())

function main()
    N=readint()
    t=0
    Smax=1

    function tcount(x)
        t=0
        for i in 1:x
            t+=26^i
        end
        t
    end

    for i in 1:11
        if N <= tcount(i)
            Smax=i
            break
        end
    end

    s=zeros(Int,Smax)
    tmp=N-tcount(Smax-1)-1

    for i in Smax:-1:1
        s[i]=tmp÷26^(i-1)
        tmp-=s[i]*26^(i-1)
    end

    for i in Smax:-1:1
        print('a'+s[i])
    end
end
main()

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


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

int n,k;
cin>>n>>k;
int h[n];int ans[n]={};
for(int i=0;i<n;i++)
{
    cin>>h[i];
}
ans[0]=0;int cnt;
ans[1]=abs(h[1]-h[0]);
for(int i=2;i<=min(n,k);i++)
{   cnt = INT_MAX;
   for(int j=0;j<i;j++)
    {
        if(ans[j]+ abs(h[i]-h[j]) <= cnt)
        {
            cnt = ans[j]+ abs(h[i]-h[j]);
        }
    }
    ans[i]=cnt;
}
for(int i=k+1;i<n;i++)
{ cnt = INT_MAX;
    for(int j=i-k;j<i;j++)
    {
        cnt = min(cnt, ans[j]+ abs(h[i]-h[j]));
    }
    ans[i]=cnt;
}
cout<<ans[n-1];
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = Long.valueOf(sc.next().replace(".", ""));
        long ans = a * b / 100;
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 35796
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N,M,X,Y;
	cin>>N>>M>>X>>Y;
	int ma=X,mi=Y;
	for(int i=0;i<N;i++)
	{
		int a;
		cin>>a;
		if(a>=ma)ma=a;
	}
	for(int i=0;i<M;i++)
	{
		int b;
		cin>>b;
		if(b<=mi)mi=b;
	}
	if(ma<mi){
		cout<<"No War"<<endl;
	}
	else{
		cout<<"War"<<endl;
	}
	return 0;
}

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

int main() {
    constexpr ll MOD = 998244353;

    ll N;
    cin >> N;
    vector<ll> a(N);
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
    }

    ll sum = accumulate(a.begin(), a.end(), (ll)0);

    vector<vector<ll>> dp1(N + 1, vector<ll>(sum + 1, 0));
    vector<vector<ll>> dp2(N + 1, vector<ll>(sum + 1, 0));

    ll ans = 1;

    for (ll i = 0; i < N; i++) {
        //全通りは3のN乗
        (ans *= 3) %= MOD;

        //rが0ならそれまでのものはg or bに振り分けられていた→2のi乗
        dp1[i][0] = (i == 0 ? 1 : dp1[i - 1][0] * 2 % MOD);

        //dp2はgしか使わないので1で初期化
        dp2[i][0] = 1;

        for (ll j = 0; j <= sum; j++) {
            //a[i]をr以外に足す
            //dp1ではg or bに足す(2倍される)
            (dp1[i + 1][j] += dp1[i][j] * 2) %= MOD;

            //dp2ではgに足す(1倍のまま)
            (dp2[i + 1][j] += dp2[i][j]) %= MOD;

            if (j + a[i] > sum) {
                continue;
            }

            //a[i]をrに足す
            (dp1[i + 1][j + a[i]] += dp1[i][j]) %= MOD;
            (dp2[i + 1][j + a[i]] += dp2[i][j]) %= MOD;
        }
    }

    for (ll i = (sum + 1) / 2; i <= sum; i++) {
        ans = (ans + MOD - dp1[N][i] * 3 % MOD) % MOD;
    }

    if (sum % 2 == 0) {
        //重複して引きすぎたものを戻す
        ans = (ans + dp2[N][sum / 2] * 3 % MOD) % MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 423872
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int n = sc.nextInt();
        final int k = sc.nextInt();
        final int r = sc.nextInt();
        final int s = sc.nextInt();
        final int p = sc.nextInt();
        final String t = sc.next();

        final char[] hands = {'r', 's', 'p'};

        final Map<Character, Character> bestChoiceMap = new HashMap<>();
        bestChoiceMap.put('r', 'p');
        bestChoiceMap.put('s', 'r');
        bestChoiceMap.put('p', 's');

        long ans = 0;
        final char[] actual = new char[n];
        for (int i = 0; i < n; i++) {
            final char prevHand = i - k >= 0 ? actual[i-k] : 0;
            final char c = t.charAt(i);
            final char nextC = i + k < n ? t.charAt(i+k) : 0;

            actual[i] = bestChoiceMap.get(c);

//            System.out.println(c + ":" + actual[i]);
            if (actual[i] == prevHand) {
                for (char hand : hands) {
                    if ((nextC == 0 || hand != bestChoiceMap.get(nextC)) && hand != prevHand) {
                        actual[i] = hand;
                    }
                }
            }

            if (actual[i] == 'r' && c == 's') ans += r;
            if (actual[i] == 's' && c == 'p') ans += s;
            if (actual[i] == 'p' && c == 'r') ans += p;
//            System.out.println(c + ":" + actual[i]);
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 28200
#include "bits/stdc++.h"
// Custom Header {{{
#define all(x)      x.begin(), x.end()
#define rep(i,n)    for (i64 i = 0; i < (n); ++i)
#define reps(i,s,t) for (i64 i = (s); i <= (t); ++i)
#define repr(i,s,t) for (i64 i = (n); i >= (t); --i)
#define LF          '\n'

#ifdef DBG
#define err(...)    fprintf(stderr, __VA_ARGS__)
#define dump(x)     clog << std::setw(6) << (#x) << ": " << (x) << endl
#else
#define err(...)
#define dump(x)
#endif

using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template<class T, class U>inline bool chmax(T &a, const U &b){return b>a ? (a=b,1) : 0;}
template<class T, class U>inline bool chmin(T &a, const U &b){return b<a ? (a=b,1) : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template<class T>
ostream& operator<< (ostream &os, const vector<T> &vec) {
    rep(i, vec.size()) os << vec[i] << (i+1 == vec.size() ? "" : " ");
    return os;
}

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

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);
    int N;
    map<string, int> cnt;

    cin >> N;
    rep(i, N) {
        string s; cin >> s;
        sort(all(s));
        cnt[s] += 1;
    }

    i64 ans = 0;
    for (const auto &e : cnt) {
        i64 n = e.second;
        ans += n * (n-1) / 2;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 11136
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	String S;
	int count = 0;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		S = in.readLine();
	}

	void calc() {
		for (int i = 0; i < S.length() / 2; ++i) {
			if (S.charAt(i) != S.charAt(S.length() - 1 - i)) {
				++count;
			}
		}
	}

	void showResult() {
		System.out.println(count);
	}
}


Measured memory_bytes: 21332
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if(abs(B-A) >= abs(C-A) && (B-A)*(C-A)>=0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = LI()
B = []
for i in range(N):
    if A[i] != 0:
        B.append(A[i])
N = len(B)
P = 200003

# 2はPの原始根

C = []  # C[i] = (2**i mod P)
d = {}  # d[n] = (2**i == n たるi)
a = 1
for i in range(P-1):
    C.append(a)
    d[a] = i
    a *= 2
    a %= P

D = [0]*(P-1)
for i in range(N):
    D[d[B[i]]] += 1

n = 2**((2*P-3).bit_length())
D += [0]*(n-(P-1))


from cmath import pi,exp

def dfs(f,start,step,N,inverse=False):
    if N == 2:
        a,b = f[start],f[start+step]
        return [a+b,a-b]
    if inverse is False:
        f0 = dfs(f,start,2*step,N//2,inverse=False)
        f1 = dfs(f,start+step,2*step,N//2,inverse=False)
        z = exp(2j*pi/N)
    else:
        f0 = dfs(f,start,2*step,N//2,inverse=True)
        f1 = dfs(f,start+step,2*step,N//2,inverse=True)
        z = exp(-2j*pi/N)
    z0 = 1.0
    for i in range(N//2):
        a,b = f0[i],f1[i]*z0
        f0[i],f1[i] = a+b,a-b
        z0 *= z
    return f0+f1

def DFT(f,N):  # fを離散フーリエ変換
    if N == 1:
        return f
    return dfs(f,0,1,N)

def iDFT(F,N):  # Fを離散フーリエ逆変換
    if N == 1:
        return F
    f = dfs(F,0,1,N,inverse=True)
    for i in range(N):
        f[i] /= N
    return f

# deg(f)+deg(g)<Nとなる2冪Nを選び、f,gの長さがNになるように0を埋めておく

def product(f,g,N):  # 多項式f,gの積
    F = DFT(f,N)
    G = DFT(g,N)
    FG = [F[i]*G[i] for i in range(N)]
    fg = iDFT(FG,N)
    for i in range(N):
        fg[i] = int(fg[i].real+0.5)
    return fg


E = product(D,D,n)
ans = 0
for i in range(P-1):
    ans += (C[i]*(E[i]+E[i+(P-1)]))

for i in range(N):
    ans -= (B[i]**2) % P

print(ans//2)


Measured memory_bytes: 284132
#include <bits/stdc++.h>
    #include <cstring>
    using namespace std;
    int main(){
    	char a[3],b[3],c[7];
    	while(cin>>a>>b){
    		int lena = strlen(a);
    		int lenb = strlen(b);
    		for(int i=0; i<lena; ++i)c[i]=a[i];
    		for(int i=0; i<lenb; ++i){
    			c[lena]=b[i];
    			lena++;
    		}
    		int x=atoi(c);
    		if(sqrt(x)==(int)sqrt(x))cout<<"Yes"<<endl;
    		else cout<<"No"<<endl;
     
    	}
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N,A,B,p1,p2;
  
  cin >> N >> A >> B;
  
  p1 = N*A;
  p2 = B;

  if (p1<p2)
  {
    cout << p1 << endl;
  }
  else if(p1>p2)
  {
    cout << p2 << endl;
  }
  else
  {
    cout << p2 << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_N 50000
#define MAX_SQRT_N 224
#define MAX_P 5140

bool f[MAX_N + 1] = {0};
int primes[MAX_P];
int np;

int
main(int argc, char **argv)
{
	int i, j;

	np = 0;
	for (i = 2; i <= MAX_N; ++i)
	{
		if (!f[i])
		{
			primes[np++] = i;
			if (i <= MAX_SQRT_N)
			{
				for (j = i + i; j <= MAX_N; j += i)
					f[j] = true;
			}
		}
	}

	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == 0)
			break;

		int count = 0;
		for (i = 0; primes[i] <= n / 2; ++i)
		{
			if (n - primes[i] >= 2 && !f[n - primes[i]])
				count++;
		}

		printf("%d\n", count);
	}

	return 0;
}

Measured memory_bytes: 668
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,m,sum=0,i,j,ans,y;
    ll t[100000],p[100000],x[100000];
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>t[i];
        sum+=t[i];
    }
    cin>>m;
    for(j=0;j<m;j++)
    {
        cin>>p[j]>>x[j];
    }
    for(i=0;i<m;i++)
    {
        y=p[i];
        ans=sum-t[y-1]+x[i];
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 2304
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p.sort()
q.sort()
r.sort()
ans=0

z=x+y

while(z!=0):
    while((x!=0)and(y!=0)):
            a=[]
            a.append(p[-1])
            a.append(q[-1])
            a.append(r[-1])
            if max(a)==p[-1]:
                x-=1
                z-=1
                ans+=p[-1]
                p.pop()
            elif max(a)==q[-1]:
                y-=1
                z-=1
                ans+=q[-1]
                q.pop()
            else:
                z-=1
                ans+=r[-1]
                r.pop()
            if z==0:
                break
            if  len(r)==0:
                break
    if len(r)==0:
        break
    if z==0:
        break
        
    if x==0:
        if q[-1]>=r[-1]:
            y-=1
            z-=1
            ans+=q[-1]
            q.pop() 
        else:
            z-=1
            ans+=r[-1]
            r.pop()
            
            
    elif y==0:
        if p[-1]>=r[-1]:
            x-=1
            z-=1
            ans+=p[-1]
            p.pop()
        else:
            z-=1
            ans+=r[-1]
            r.pop()

            
            
if len(r)==0:
    while(z!=0):
        while((x!=0)and(y!=0)):
            a=[]
            a.append(p[-1])
            a.append(q[-1])
            if max(a)==p[-1]:
                x-=1
                z-=1
                ans+=p[-1]
                p.pop()
            elif max(a)==q[-1]:
                y-=1
                z-=1
                ans+=q[-1]
                q.pop()
            if z==0:
                break
        if z==0:
            break
        if x==0:
            y-=1
            z-=1
            ans+=q[-1]
            q.pop() 
        else: 
            x-=1
            z-=1
            ans+=p[-1]
            p.pop()
        
        
        
        
        
        
        
        
        
        
        
        
        
print(ans)

Measured memory_bytes: 23692
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  //acceleration
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  //initialization
  long long lim = 1000000000000000000;
  long double  ans = 1;
  
  int n;
  cin >> n;
  long long input;
 
  //calculation
  for(int i = 0; i < n ; i++){
    cin >> input;
   
    // input 0
    if(input == 0){
      ans = 0;
      cout << 0 << "\n";
      return 0;
    }
     
    if(ans != -1){
      ans *= input;
    }
    // over the limit answer
    if(lim < ans || ans < 0){
      ans = -1; 
    }
  }
 
  cout << (long long)ans << "\n";
}

Measured memory_bytes: 3640
import math
N,D = map(int,input().split())
X = [[] for _ in range(N)]
for i in range(N):
    X[i] = list(map(int,input().split()))

count = 0
distance = 0

for i in range(N-1):
    for j in range(i+1,N):
      distance = 0
      for k in range(D):
        distance += pow(X[i][k] - X[j][k],2)
      distance = math.sqrt(distance)
      f = distance - int(distance)
      if f == 0.0:
        count += 1
            
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
 
const int maxn=2e3+10,maxn2=2*2e3+10;
int n,a[maxn2],dp[maxn][maxn],rnkw[maxn],rnkb[maxn];
int bit[maxn2];
char c[maxn2][2];
 
inline void add(int pos,int val){
	while(pos<maxn2){
		bit[pos]+=val;
		pos+=pos&-pos;
	}
}
inline int sum(int pos){
	int res=0;
	while(pos){
		res+=bit[pos];
		pos-=pos&-pos;
	}
	return res;
}
inline void chkmin(int&a,int b){
	if(a>b)a=b;
}
 
int main(){
	cin>>n;
	for(int i=1;i<=2*n;++i){
		cin>>c[i]>>a[i];
		if(c[i][0]=='W')
			rnkw[a[i]]=i;
		else
			rnkb[a[i]]=i;
	}
	for(int i=0;i<=n;++i)
		for(int j=0;j<=n;++j)
			dp[i][j]=1e9;
	dp[0][0]=0;
	for(int i=1;i<=n;++i)
		add(rnkw[i],1);
	for(int i=0;i<=n;++i){
		if(i)
			add(rnkw[i],-1);
		for(int j=1;j<=n;++j)
			add(rnkb[j],1);
		for(int j=0;j<=n;++j){
			if(j)
				add(rnkb[j],-1);
			if(i<n)
				chkmin(dp[i+1][j],dp[i][j]+sum(rnkw[i+1])-1);
			if(j<n)
				chkmin(dp[i][j+1],dp[i][j]+sum(rnkb[j+1])-1);
		}
	}
	cout<<dp[n][n]<<endl;
	return 0;
}

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


int main(){
  int n,k;
  cin>>n>>k;
  set<int> ans;
  rep(i,k){
    int x;
    cin>>x;

    rep(j,x){
      int y;
      cin>>y;
      ans.insert(y);
    }

  }
  cout<<n - ans.size()<<endl;


}


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

string field[20];

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
string dir_str = ">^<v";
string dir_str2 = "RULD";

#define DBG(x) cout<<#x<<": "<<x<<endl;

int main() {
	int N;
	cin >> N;
	while(N--) {
		int H, W;
		
		cin >> H >> W;
		
		cin.ignore();
		
		for(int y = 0; y < H; y++) {
			getline(cin, field[y]);
		}
		
		int curX, curY, dir;
		
		for(int y = 0; y < H; y++) {
			for(int x = 0; x < W; x++) {
				if(find(dir_str.begin(), dir_str.end(), field[y][x]) != dir_str.end()) {
					dir = find(dir_str.begin(), dir_str.end(), field[y][x]) - dir_str.begin();
					curX = x;
					curY = y;
				}
			}
		}
		
		/*
		DBG(curX);
		DBG(curY);
		DBG(dir);
		*/
		
		int len_cmd; string cmd;
		cin >> len_cmd >> cmd;
		
		for(int cn = 0; cn < len_cmd; cn++) {
			char c = cmd[cn];
			if(find(dir_str2.begin(), dir_str2.end(), c) != dir_str2.end()) {
				int d = find(dir_str2.begin(), dir_str2.end(), c) - dir_str2.begin();
				
				dir = d;
				field[curY][curX] = dir_str[d];
				
				int nx = curX + dx[d];
				int ny = curY + dy[d];
				
				if(0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx] == '.') {
					field[curY][curX] = '.';
					field[ny][nx] = dir_str[d];
					curX = nx;
					curY = ny;
				}
			}
			
			if(c == 'S') {
				int nx = curX + dx[dir];
				int ny = curY + dy[dir];
				
				while(0 <= nx && nx < W && 0 <= ny && ny < H) {
					
					if(field[ny][nx] == '*') {
						field[ny][nx] = '.';
						break;
					}
					
					if(field[ny][nx] == '#') {
						break;
					}
						
					nx += dx[dir];
					ny += dy[dir];
					
				}
			}
			/*
			cout << "turn: " << cn << endl;
			
			DBG(curX);
			DBG(curY);
			DBG(dir);
			
			for(int y = 0; y < H; y++) {
				cout << field[y] << endl;
			}
			*/
		}
		
		for(int y = 0; y < H; y++) {
			cout << field[y] << endl;
		}
		
		if(N > 0) {
			cout << endl;
		}
	}
	return 0;
}

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

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

  sort(h.begin(), h.end());
  ll ans = pow(10,9)+1;
  for (int i = k-1; i < n; i++) {
    ans = min(ans, h[i]-h[i-k+1]);
    if (ans == 0) break;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<long long> suma(n + 1);
  suma[0] = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i == 0)
      suma[i + 1] = a[i];
    else
      suma[i + 1] = suma[i] + a[i];
  }
  vector<int> b(m);
  vector<long long> sumb(m + 1);
  sumb[0] = 0;
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    if (i == 0)
      sumb[i + 1] = b[i];
    else
      sumb[i + 1] = sumb[i] + b[i];
  }
  int ans = 0;
  for (int i = 0; i < n + 1; i++) {
    if (suma[i] > k) break;
    for (int j = m; j >= 0; j--) {
      if (suma[i] + sumb[j] <= k) {
        ans = max(ans, i + j);
        m = j;
        break;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 7916
#include <stdio.h>
/********
*	??????????????¨????????????
*********/

/*********??¢?????´?????????
*	(1)????¬????????????¨????¬??????????????????????
*	(2)????¬?????????????????¬????????????¨?????????
*	(3)
*********/

int main(void)
{
	int n, m;			//?????°n????????°m
	int a, b, c;
	int i, j;
	int gyouretu_a[101][101]={{0}}, gyouretu_b[101]={0}, gyouretu_c[101]={0};
	
	scanf("%d %d\n", &n, &m);

	for(i=1; i<= n; i++){		//A?????\???
		for(j=1; j<= m; j++){
			scanf("%d", &a);
			gyouretu_a[i][j] = a;

			if(j < (m-1)){
				scanf(" ");
			}else if(j ==m){
				scanf("\n");
			}else{
			//??????????????\??????
			}
		}
	}
	
	for(i=1; i<= m; i++){		//b?????\???
			scanf("%d\n", &b);
			gyouretu_b[i] = b;
	}

	for(i=1; i <= n; i++){
		for(j=1; j<= m; j++){
			gyouretu_c[i] += (gyouretu_a[i][j])* (gyouretu_b[j]);
		}
	}
	
	
	for(j=1; j <= n; j++){		//???????????????
		c = gyouretu_c[j];
		printf("%d\n", c);
	}
	
    return 0;
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
ll a[200010];
int main() {
    ll sum=0,n;
    cin>>n;
    for(ll i=1;i<=n;i++)    scanf("%d",&a[i]),sum^=a[i];
    for(ll i=1;i<=n;i++)    printf("%d ",sum^a[i]);
    return 0;
}


Measured memory_bytes: 4556
while True:
    h,w = map(int, input().split())
    if h == 0 and w == 0:
        break
    else:
        for i in range(h):
            if i == 0 or i+1 == h:
                print("#"*w)
            else:
                print("#"+"."*(w-2)+"#")
        print()


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int main(){
  int n;
  cin>>n;
  int r = n%10;
  set<int> hon,bon,pon;
  
  string s;
  if(r==3){
    s="bon\n";
  } else if(r==0 || r==1 || r==6 || r==8){
    s="pon\n";
  } else if(r==2 || r==4 || r==5 || r==7 || r==9){
    s="hon\n";
  }
  cout<<s;
}

Measured memory_bytes: 3620
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/12/20 20:48:37
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  constexpr ll MINF = -1e15;

  int n; cin>>n;
  vector<ll> A(n); for(auto& a:A) cin>>a;
  vector<array<ll, 2>> dp(n);
  dp[0] = {A[0], 0};
  dp[1] = {max(A[0], A[1]), MINF};
  for (int i = 2; i < n; i++) {
    if (i%2==0) {
      dp[i][0] = dp[i-2][0]+A[i];
      dp[i][1] = max(dp[i-1][0], dp[i-2][1]+A[i]);
    } else {
      dp[i][0] = max(dp[i-1][0], dp[i-2][0]+A[i]);
      dp[i][1] = MINF;
    }
    cerr<<dp[i][0]<<" "<<dp[i][1]<<endl;
  }
  auto ans = dp[n-1][n%2];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11504
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS

vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int n;
cin>>n;
string s;
cin>>s;
map<char,set<int>> l,r;
FOR(i,0,s.size()) {
	r[s[i]].insert(i);
}
int ans = 0;
l[s[0]].insert(0);
r[s[0]].erase(0);
FOR(i,1,n-1) {
	r[s[i]].erase(i);
	if(s[i] == 'R') {
		int val = 0;
		for(auto val : l['G']) if(r['B'].find(2*i-val) != r['B'].end()) ans--;
		ans+=(l['G'].size()*r['B'].size());
		for(auto val : l['B']) if(r['G'].find(2*i-val)!=r['G'].end()) ans--;
		ans+=(l['B'].size()*r['G'].size());
	} else if(s[i] == 'G') {
		for(auto val : l['R']) if(r['B'].find(2*i-val) != r['B'].end()) ans--;
		ans+=(l['R'].size()*r['B'].size());
		for(auto val : l['B']) if(r['R'].find(2*i-val)!=r['R'].end()) ans--;
		ans+=(l['B'].size()*r['R'].size());
	} else {
		for(auto val : l['R']) if(r['G'].find(2*i-val) != r['G'].end()) ans--;
		ans+=(l['R'].size()*r['G'].size());
		for(auto val : l['G']) if(r['R'].find(2*i-val)!=r['R'].end()) ans--;
		ans+=(l['G'].size()*r['R'].size());
	}
	l[s[i]].insert(i);
}
cout<<ans;
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 3824
n = int(input())
a = map(int,input().split())
alists = []
num = 0

for i in a:
    alists.append(abs(i))
    if i < 0:
        num = num + 1
        
if num % 2 == 1:
    print(sum(alists)-min(alists)*2)
else:
    print(sum(alists))

Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int N, ans=0;
    cin >> N;
    for(int i=0; i<26; i++){
        for(int j=0; j<15; j++){
            if(N == 4*i + 7*j) ans++;
        }
    }
    if(ans>0){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    
}

Measured memory_bytes: 256
import java.util.*;

class Main {

    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        int e = scan.nextInt();
        int f = 0;
        if (a < b && a < c) {
            f = a;
        } else if (b < c) {
            f = b;
        } else {
            f = c;
        }
        if (d < e) {
            f = f + d - 50;
        } else {
            f = f + e - 50;
        }
        System.out.println(f);
    }
}



Measured memory_bytes: 26264
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;


int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	int k, x;
	cin >> k >> x;
	for (int i = x - k + 1; i < x + k; i++)
		cout << i << " ";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        String str[]=br.readLine().split(" ");
        int s=Integer.parseInt(str[0]);
        int w=Integer.parseInt(str[1]);
        if(s<=w)
        pw.println("unsafe");
        else
        pw.println("safe");
        pw.flush();
        pw.close();
    }
}

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

main()
{
    int n; cin >> n;
    double p[n];
    for(int i=0;i<n;i++) cin >> p[i];
   // cout << 1.0-p[0] << endl;
    double dp[n+1][n+1];
    memset(dp,0,sizeof(dp));

    dp[0][0]=1.0;

    for(int i=1;i<=n;i++)
    {
        dp[i][0]=dp[i-1][0]*(1.0-p[i-1]); //when j=0, means out of ith coin all are tails so just keep cumulatively multiplying tails prob.
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            // two cases
            // 1.Till i-1th coin we've J heads so this coin must be tail
            // 2.Till i-1th coin we've j-1 heads so this coin must be heads
            dp[i][j]=dp[i-1][j]*(1.0-p[i-1]) + dp[i-1][j-1]*p[i-1];
        }
    }


    double ans=0.0; 
    
    for(int i=n/2+1;i<=n;i++)
    {
        ans+=dp[n][i];
    }
    cout << setprecision(10)<< ans << endl;

}

Measured memory_bytes: 70528
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	int zp(int i,int j){

		int ret = 0;

		ret += i%3;

		ret *= 3;

		ret += j%3;

		return ret;

	}

	int zy(int i, int j, int z){

		int ret = 0;

		ret += j/3;

		ret *= 3;

		ret += z%3;

		return ret;

	}

	int zx(int i, int j, int z){

		int ret = 0;

		ret += i/3;

		ret *= 3;

		ret += z/3;

		return ret;

	}

	

	void run(){

		int n = sc.nextInt();

		for(int x =0; x < n ; x++){

			if(x!=0){

				System.out.println();

			}

			int map[][] = new int[9][9];

			for(int i = 0; i < 9 ; i++){

				for(int j = 0; j < 9; j++){

					map[i][j] = sc.nextInt();

				}

			}

			for(int i = 0; i < 9 ; i++){

				for(int j = 0; j < 9; j++){

					boolean aster = false;

					for(int k = 0 ; k < 9 ; k ++){

						if(i == k)

							continue;

						aster = aster || (map[k][j] == map[i][j]);

					}

					for(int k = 0 ; k < 9 ; k ++){

						if(j == k)

							continue;

						aster = aster || (map[i][k] == map[i][j]);

					}

					for(int z = 0 ; z < 9; z ++){

						if(z == zp(i, j))

							continue;

						aster = aster || (map[i][j] == map[zx(i,j,z)][zy(i,j,z)]);						

					}

					System.out.print(aster?'*':' ');

					System.out.print(map[i][j]);

				}

				System.out.println();

			}

			

		}		

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 13000
#include<stdio.h>
#define MAX 100000
typedef long long llong;
int n, k;
llong T[MAX];
 
int check(llong P){
  int i = 0, j;
  for(j = 0; j < k; j++){
    llong s = 0;
    while(s + T[i] <= P){
      s += T[i];
      i++;
      if(i == n) return n;
    }
  }
  return i;
}
 
int solve(){
  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  int v;
  while(right - left > 1){
    mid = (left + right) / 2;
    v = check(mid);
    if(v >= n) right = mid;
    else left = mid;
  }
 
  return right;
}
 
int main(){
  int i;
  scanf("%d%d",&n,&k);
  for(i = 0; i < n; i++) scanf("%d",&T[i]);
  llong ans = solve();
  printf("%d\n",ans);
 
  return 0;
}

Measured memory_bytes: 2560