akhauriyash/Code-Regression huggingface dataset:
H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
L=[[0]*W for i in range(H)]
R=[[0]*W for i in range(H)]
U=[[0]*W for i in range(H)]
D=[[0]*W for i in range(H)]
res=0
for i in range(H):
    for j in range(W):
        if(S[i][j]=='#'):
            L[i][j]=0
        elif(j==0):
            L[i][j]=1
        else:
            L[i][j]=L[i][j-1]+1
    for j in reversed(range(W)):
        if(S[i][j]=='#'):
            R[i][j]=0
        elif(j==W-1):
            R[i][j]=1
        else:
            R[i][j]=R[i][j+1]+1
for j in range(W):
    for i in range(H):
        if(S[i][j]=='#'):
            U[i][j]=0
        elif(i==0):
            U[i][j]=1
        else:
            U[i][j]=U[i-1][j]+1
    for i in reversed(range(H)):
        if(S[i][j]=='#'):
            D[i][j]=0
        elif(i==H-1):
            D[i][j]=1
        else:
            D[i][j]=D[i+1][j]+1
for i in range(H):
    for j in range(W):
        res=max(res,U[i][j]+D[i][j]+L[i][j]+R[i][j]-3)
print(res)

Measured memory_bytes: 309768
n=list(input())
k=2**(len(n)-1)
v=[]
for i in range(k):
    x=['+']*(len(n)-1)
    for j in range(len(n)-1):
        if (i>>j)&1:
            x[j]=''
    
    ans=''
    for a,b in zip(n,x+['']):
        ans+=(a+b)
    v.append(eval(ans))
print(sum(v))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;

int main(){
  int a,b,c;
  int t = 0,h = 0;
  while(scanf("%d,%d,%d",&a,&b,&c) != EOF){
    if(a*a+b*b == c*c) t++;
    else if(a == b) h++;
  }
  cout << t << endl << h << endl;
}

Measured memory_bytes: 1208
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = 0; i < k; i++)
    {
        if (i % 2 == 0)
        {
            a /= 2;
            b += a;
        }
        else
        {
            b /= 2;
            a += b;
        }
    }
    cout << a << " " << b;
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long long modp(long long a, long long p) {
    long long res = a % p;
    if (res < 0) res += p;
    return res;
}

int main(void){
    int N,M; cin >> N >> M;
    string s; cin >> s;
    int n[N+1]; REP(i,N+1) n[i] = (int)INF;
    n[N] = 0;
    int ptr = N, num=1;
    while(ptr > 0){
        int nxt = ptr;
        REP(i,M){
            if(ptr-(i+1) < 0) break;
            if(s[ptr-(i+1)] == '1') continue;
            n[ptr-(i+1)] = num;
            nxt = ptr-(i+1);
        }
        if(nxt == ptr){
            cout << "-1" << endl;
            return 0;
        }
        ptr = nxt;
        num++;
    }
    vector<int> ans;
    ptr = 0;
    int nxt = n[0]-1;
    while(ptr < N){
        int prev = ptr;
        while(n[ptr] != nxt) ptr++;
        ans.push_back(ptr-prev);
        nxt--;
    }
    for(int v : ans) cout << v << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1528
import math
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
  x=math.degrees(math.atan2(l[i][1], l[i][0]))
  l[i]=[x,l[i][0],l[i][1]]
l.sort()
L=l+l
ansL=[]
for i in range(n):
  for j in range(i,n+i):
    ctx=0;cty=0
    for k in range(i,j+1):
      ctx+=L[k][1]
      cty+=L[k][2]
    ansL.append((ctx**2+cty**2)**0.5)
print(max(ansL))

Measured memory_bytes: 3444
#include <iostream>

using namespace std;

int main() {
    unsigned long long X;
    cin >> X;

    for (unsigned long long n = 1; n <= X; n++) {
        unsigned long long sum_of_arithmetic_progression = n * (n + 1) / 2;
        if (sum_of_arithmetic_progression >= X) {
            cout << n << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A,B;
    scanf("%d %d",&A,&B);
    if(A>=13)
        printf("%d\n",B);
    else if(A>=6&&A<=12)
        printf("%d\n",B/2);
    else if(A>=0&&A<=5)
        printf("0\n");



}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
long long gcd(long long a,long long b)
{

return b==0?a:gcd(b,a%b);
}

long long lcm(long long a,long long b)
{
return a/gcd(a,b)*b;
}
int main()
{
long long a,b,c,d;
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
long long t,tt,kk,k,sum;
long long ans=0;
t=b/c-(a-1)/c;
k=b/d-(a-1)/d;
tt=lcm(c,d);
kk=b/tt-(a-1)/tt;

sum=b-a+1-t-k+kk;
printf("%lld\n",sum);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int a, b;
  scanf("%d\n", &a);
  scanf("%d\n", &b);
  int max = 0;
  for (size_t i = 0; i < 2; i++) {
    if (a >= b) {
      max += a;
      a--;
    } else {
      max += b;
      b--;
    }
  }
  printf("%d", max);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
  int n,a,b,r=0;
  scanf("%d%d%d", &n,&a,&b);
  for (int i =1; i <= n; i++) {
    int c =0, t = i;
    for (int j= 0; j < 5; j++) {
      c += t % 10;
      t /= 10;
    }
    if (c >= a && c <= b) r += i;
  }
  printf("%d",r);
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define rep2r(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int N; ll K; cin >> N >> K;
  vector<ll> A(N); rep(i, N) cin >> A[i];
  vector<ll> B(N); rep(i, N) cin >> B[i];
  sort(range(A));
  sort(range(B), greater<>());
  ll l = -1;
  ll r = (ll)1e12;
  while (r - l > 1) {
    ll m = (l + r) / 2;
    ll cost = 0;
    ll k = K;
    bool ok = true;
    rep(i, N) {
      // (A[i] - k) * B[i] <= m
      // (A[i] * B[i] - m) / B[i] <= k
      ll use = max(0LL, A[i] * B[i] - m + B[i] - 1) / B[i];
      if ((A[i] - k) * B[i] > m) ok = false;
      k -= use;
    }
    if (ok) r = m; else l = m;
  }
  cout << r << endl;
}

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

int main(){
  int N,cur=0,a;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a;
    if(cur+1==a){
      cur ++;
    }
  }
  if(cur == 0){
    cout << -1 << endl;
  }else{
    cout << N - cur << endl;
  }
}

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

int main(){
    int64_t H,N;
    cin >> H >> N;
    int64_t A[N];
    int64_t ans = 0;
    for ( int64_t i = 0; i < N; ++i){
        cin >> A[i];
    }
    for ( int64_t i = 0; i < N; ++i){
        ans += A[i];
    }
    
    if ( ans >= H ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		d, _ := strconv.Atoi(sc.Text())
		var area int
		for i := 1; i*d < 600; i++ {
			area += d * (d * i) * (d * i)
		}
		fmt.Println(area)
	}
}



Measured memory_bytes: 1092
<?php
/**
 * ABC123
 * D - Cake 123
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, "%d %d %d %d", $x, $y, $z, $k);
$a_list = array_map('intval', explode(' ', trim(fgets(STDIN))));
$b_list = array_map('intval', explode(' ', trim(fgets(STDIN))));
$c_list = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ab_list = [];
foreach ($a_list as $a) {
    foreach ($b_list as $b) {
        $ab_list[] = $a + $b;
    }
}

rsort($ab_list);
$ab_list = array_slice($ab_list, 0, $k, true);

$abc_list = [];
foreach ($ab_list as $key => $ab) {
    foreach ($c_list as $c) {
        $abc_list[] = $ab + $c;
    }
}

rsort($abc_list);
$abc_list = array_slice($abc_list, 0, $k, true);

foreach ($abc_list as $abc) {
    echo $abc, PHP_EOL;
}


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


def dfs(V, start):
    q = [(start, 0)]
    used = [False] * (n+1)
    farthest = 0
    pos = 0

    while q:
        s, cost = q.pop()
        if farthest < cost:
            pos = s
            farthest = cost
        used[s] = True
        for t, c in V[s].items():
            if used[t]:
                continue
            q.append((t, cost + c))
    
    return farthest, pos


if __name__ == "__main__":
    n = int(input())
    V = {i:dict() for i in range(1, n+1)}

    for _ in range(n - 1):
        s, t = map(int, input().split())
        V[s][t] = 1
        V[t][s] = 1

    if n==1:
        print("First")
    else:
        d = dfs(V, dfs(V, 1)[1])[0]
        if d==1:
            print("Second")
        elif d==2:
            print("First")
        elif (d-1)%3==0:
            print("Second")
        else:
            print("First")


Measured memory_bytes: 133772
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S;
	cin >> S;
	if(S.size() == 1){
		cout << "No" << endl;
	return 0;
	}
	for(int i = 0; i < S.size(); i += 2){
		string sub = S.substr(i, 2);
		if(sub != "hi"){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

k, n = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

max = a[0] + k - a[-1]

(n - 1).times do |i|
  max = a[i + 1] - a[i] if max < a[i + 1] - a[i]
end

puts k - max

Measured memory_bytes: 15492
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {  
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n)cin >>p.at(i);
    int a=p.at(0);
    int ans=0;
    rep(i,n){
        if(a>=p.at(i)){
            ans++;
            a=p.at(i);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1e9;

int main() {
  int n, k, d, a;
  cin >> n >> k;
  map<int, int> ok;
  rep(i, k) {
    cin >> d;
    rep(j, d) {
      cin >> a;
      ok.insert(make_pair(a, a));
    }
  }
  cout << n - ok.size() << endl;
}


Measured memory_bytes: 3640
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

signed main() {
    int N;
    cin >> N;
    string str;
    cin >> str;

    map<int, int> m;

    for (int i = 0; i < N; i++) {
        m[str[i]]++;
    }

    int ret = 1;
    for (auto it = m.begin(); it != m.end(); it++) {
        ret *= it->second + 1;
        ret %= MOD;
    }

    cout << ((ret -1 + MOD) % MOD) << endl;

    return 0;
}

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	bool isA = false;

	if (s.at(0) == 'A') { isA = true; }

	bool isC = false;
	int count = 0;
	bool isUpper = false;
	for (int i = 2; i < s.size() - 1; i++)
	{
		
		if (isupper(s.at(i)))
		{
			if (s.at(i) == 'C')
			{
				count++;
				if (count == 1)
				{
					isC = true;
				}
				else
				{
					isUpper = true;
					break;
				}
			}
			else
			{
				isUpper = true;
				break;
			}
		}
	}
	if (isupper((char)(s.at(1))))
	{
		isUpper = true;
	}
	if (isupper((char)(s.at(s.size() - 1))))
	{
		isUpper = true;
	}

	if (isA && isC && !isUpper)
	{
		cout << "AC" << endl;
	}
	else
	{
		cout << "WA" << endl;
	}
}


Measured memory_bytes: 256
n = gets.to_i
hs = gets.split.map(&:to_i)

(0..n-2).each do |i|
  # if hs[i] > hs[i+1]
  if hs[i] > hs[i+1] || (i != 0 && hs[i] -1 >= hs[i-1])
    hs[i] -= 1
  end
end

ans = 'Yes'
(0..n-2).each do |i|
  if hs[i] > hs[i+1]
    ans = 'No'
  end
end

# puts hs.inspect

puts ans

Measured memory_bytes: 11012
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <unordered_map>
#include <array>
#include <map>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctgmath>
#include <set>
#include <queue>
#include <fstream>
#include <ostream>
#include <list>
#include <string>
using namespace std;

#define MOD 1000000007
#define int long long
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	vector<int> seq;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;

		seq.push_back(a);
	}

	vector<pair<int, int>> temp(n);
	vector<vector<pair<int, int>>> dp(n, temp);

	for (int i = 0; i < n; i++) 
	{
		dp[i][i].first = seq[i];
	}

	for (int l = 2; l <= n; l++) 
	{
		for (int i = 0; i <= n - l; i++) 
		{
			int j = i + l - 1;
			if (seq[i] + dp[i + 1][j].second > dp[i][j - 1].second + seq[j]) {
				dp[i][j].first = seq[i] + dp[i + 1][j].second;
				dp[i][j].second = dp[i + 1][j].first;
			}
			else {
				dp[i][j].first = seq[j] + dp[i][j - 1].second;
				dp[i][j].second = dp[i][j - 1].first;

			}
		}
	}
	cout << dp[0][n-1].first - dp[0][n-1].second << "\n";
}


Measured memory_bytes: 141056
#include <bits/stdc++.h> 
#define ll long long int
#define ld long double
#define ull unsigned long long
const double pi=3.14159265358979323846;
using namespace std;

bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 

ll ipow(ll base, ll exp)
{
    ll result = 1;
    for (;;)
    {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        if (!exp)
            break;
        base *= base;
    }

    return result;
}

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    ull n;
    cin>>n;
    string s;
    while (n--)
    {
        ull t=n%26;

        s.push_back('a'+t);
        n=n/26;
    }
    reverse(s.begin(),s.end());
    cout<<s<<"\n";

    
}

Measured memory_bytes: 3608
import sys
# input = sys.stdin.readline

N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

cnt = 0
table = [0] * N
for i, Si in enumerate(S):
    if i == 0: continue
    elif Si == 'C':
        if S[i - 1] == 'A':
            cnt += 1
    table[i] = cnt

for i, (li, ri) in enumerate(lr):
    ans = table[ri - 1]
    if li > 1:
        ans -= table[li - 2]
        if S[li - 2] == 'A' and S[li - 1] == 'C': ans -= 1
    print(ans)


Measured memory_bytes: 30688
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<unordered_map>
#include<vector>
#include<string>
#include<unordered_set>
#include<set>
#include<algorithm>
using namespace std;


typedef long long ll;



int main()
{
	ll n,d,d2;
	cin >> n>>d;
	d2 = d * d;
	ll x, y;
	int count = 0;
	while (n--)
	{
		cin >> x >> y;
		if (x * x + y * y <= d2) count++;
	}
	cout << count << endl;
	

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
int main(){
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    bool map[h][w];
    for(int i=0;i<w-a;i++){
        for(int j=0;j<h-b;j++){
           map[j][i]=0;
        }
    }
    for(int i=h-b;i<h;i++){
        for(int j=w-a;j<w;j++){
            map[i][j]=0;
        }
    }
    for(int i=h-b;i<h;i++){
        for(int j=0;j<w-a;j++){
            map[i][j]=1;
        }
    }
    for(int i=0;i<h-b;i++){
        for(int j=w-a;j<w;j++){
            map[i][j]=1;
        }
    }
    rep(i,h){
        rep(j,w){
            cout << map[i][j];
        }
        cout << endl;
    }
}



Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    
    int difference = b - a;
    
    int west_height = 0;
    for(int i = 1; i < difference; i++){
        west_height += i;
    }
    
    cout << west_height - a << endl;
}

Measured memory_bytes: 256
n = int(input())
answer1 = 0
answer2 = 0
answer = 0
a = [0]*n
b = [0]*n
x = 0
y = 0
for i in range(n):
  x,y = map(int,input().split())
  a[i] = x-y
  b[i] = x+y
answer1 = max(a)-min(a)
answer2 = max(b)-min(b)
print(max(answer1,answer2))

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

int main()
{
	int n, t, a;
	cin >> n >> t >> a;
	t *= 1000;
	a *= 1000;
	int ret = 1;

	int h;
	cin >> h;

	int check = abs((t - 6 * h) - a);
	for (int i = 2; i <= n; ++i) {
		cin >> h;
		int temp = abs((t - 6 * h) - a);
		if (temp < check) {
			check = temp;
			ret = i;
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<deque>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<sstream>
using namespace std;
#define pi acos(-1.0) 
#define ms(x,n) memset(x,n,sizeof(x));
#define pb push_back
typedef long long ll;//string::npos
typedef long long iint;
ll gcd(ll a,ll b){ return a%b==0?b:gcd(b,a%b); }
const int inf=0x3f3f3f3f;
const int maxn=2e5+5;
const int mod=998244353;
//priority_queue<ll,vector<ll>,greater<ll> > q;//小根堆 
//vector<int> vt;
//pair<int,int> p;
//map<int,int> m; 
int main() {
	ios::sync_with_stdio(false);
	
	iint n;
	cin>>n;
	long long sum=0;
	for(int i=1;i<=n;i++){
		if(i%3==0||i%5==0){
			;
		}else{
			sum+=i;
		}
	}
	cout<<sum<<endl;
	
	
}

Measured memory_bytes: 3648
'use strict';
(function(stdin) {
  var inputs  = stdin.toString();
  var S = parseInt(inputs.split('\n')[0],10);
  var h = Math.floor(S / 3600);
  var m = Math.floor(S % 3600 / 60);
  var s = S % 60;
//  console.log(h+':'+m+':'+s);
  console.log([h,m,s].join(':'));

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7644
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a=0, b = 0,c,d, n, k;
string s, t;


int main()
{

	cin >> s;
	sort(all(s));
	int cnt = 0;
	rep(i, s.size() - 1)
	{
		if (s[i] == s[i + 1])
		{
			cout << "no" << endl; cnt++; break;
		}
		
	}
	if(cnt==0)
	cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 *      purpose : CODE FESTIVAL 2017 qual C B
 *      author  : kyomukyomupurin
 *      created : 2018-11-04 23:05:41
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    int A[N] = {};
    for (int i = 0; i < N; ++i) cin >> A[i];
    int x = 1;
    for (int i = 0; i < N; ++i){
        if (A[i] % 2 == 0){
            x *= 2;
        }
    }
    print(pow(3, N) - x);
    
    return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

vector<int> ans(0);
bool dfs(vector<int> cur) {
    // dump(cur);
    if (cur.size() == 0) { return true; }

    for (int i = cur.size() - 1; 0 <= i; i--) {
        if (cur[i] == i) {
            vector<int> nxt(0);
            for (int j = 0; j < cur.size(); j++) {
                if (i != j) { nxt.push_back(cur[j]); }
            }
            if (dfs(nxt)) {
                ans.push_back(i);
                return true;
            }
        }
    }

    return false;
}

int main() {
    int N;
    cin >> N;
    vector<int> prev(N, 0);
    rep(i, N) {
        cin >> prev[i];
        prev[i]--;
    }

    vector<int> ans(0);
    while (prev.size() > 0) {
        dump(prev);

        int pos = -1;
        for (int i = 0; i < prev.size(); i++) {
            if (prev[i] == i) pos = i;
        }

        if (pos == -1) {
            cout << -1 << endl;
            return 0;
        }

        ans.push_back(pos);

        vector<int> nxt(0);
        for (int i = 0; i < prev.size(); i++) {
            if (i != pos) { nxt.push_back(prev[i]); }
        }
        prev = nxt;
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[ans.size() - i - 1] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
int n, m;
int f[186][186][186][17];
char s[200][200], co[200];

void update(int &x, int y) {
	if (y > x) x = y;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
	for (int i = 0; i <= n; ++i) {
		for (int j = i; j <= n; ++j) {
				for (int k = 1; k <= m; ++k)
					if (j == i) co[k] = s[j][k];
					else co[k] = s[j][k] == co[k] ? co[k] : ' ';
				int pos = m;
				for (int k = m; k >= 1; --k) {
					if (co[k] != co[pos]) pos = k;
					if (co[k] != ' ') f[i][j][k][0] = pos;
				}
		}
	}
	for (int i = 0; i < 16; ++i) {
		for (int j = 1; j <= n; ++j)
			for (int k = j; k <= n; ++k)
				for (int l = 1; l <= m; ++l)
					if (f[j][k][l][i]) {
						int x = f[j][k][l][i];
						if (x == m || !f[j][k][x + 1][i]) update(f[j][k][l][i + 1], x);
						else update(f[j][k][l][i + 1], f[j][k][x + 1][i]);
					}
		for (int j = 1; j <= n; ++j)
			for (int k = 1; k <= m; ++k)
				for (int l = j + 1, p = j; l <= n; ++l) {
					while (p < l && f[j][p][k][i] > f[p + 1][l][k][i]) ++p;
					if (p < l) update(f[j][l][k][i + 1], min(f[j][p][k][i], f[p + 1][l][k][i]));
					if (p > i) update(f[j][l][k][i + 1], min(f[j][p - 1][k][i], f[p][l][k][i]));
				}
	}
	for (int i = 0; i <= 16; ++i)
		if (f[1][n][1][i] == m) {
			printf("%d", i); return 0;
		}
}


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

int main () {
    int a, b, c, k;
    cin >> a >> b >> c;
    cin >> k;
    for (int i = 0; i < k; i++) {
        if (a >= b) {
            b *= 2;
        } else if (b >= c) {
            c = c * 2;
        }
        if (a < b && b < c) {
            cout << "Yes" << endl;
            break;
        } else if (i == k-1) {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 3096
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;
typedef pair<double, double > P;
int main(){
    int n;
    vector < P > T;
    while(scanf("%d",&n),n){
        T.clear();
        for(int i = 0; i < n; i++){
            double m,a,b;
            scanf("%lf%lf%lf",&m,&a,&b);
            P p;
            p.first = a;
            p.second = m;
            T.push_back(p);
            p.first = b-0.1;
            p.second = -m;
            T.push_back(p);
        }
        sort(T.begin(),T.end());
        double weight = 0;
        bool flg = true;
        for(int i = 0 ; i < T.size(); i++){
            weight += T[i].second;
            if(weight > 150.0){
                flg = false;
                break;
            }
        }
        flg ? puts("OK") : puts("NG");
    }
    return 0;
}

Measured memory_bytes: 1060
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, readline().split())
    left = (K*(K-1))//2
    right = K*(2*N -K +1)//2
    ans = 0
    for i in range(K, N+1):
        ans += (right - left +1) % MOD
        right += N-i
        left += i
    print((ans+1)%MOD)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9276
#include<stdio.h>
int main(){
	int H=0,B=0;
	int a[4],b[4];
	int i,j;
	while((scanf("%d",&a[0]))!=EOF){
		scanf("%d%d%d", &a[1], &a[2], &a[3]);
		scanf("%d%d%d%d", &b[0], &b[1], &b[2], &b[3]);
		
		for(i=0;i<4;i++){
			if(a[i]==b[i]){
				H++;
			}
		}
		
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				if(a[i]==b[j]){
					if(i!=j){
						B++;
					}
				}
			}
		}
		printf("%d %d\n",H,B);
		H=0;
		B=0;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

int main(){
  int W,H,x,y,r;

  cin >> W >> H >> x >> y >> r;

  if((x < r) || (x > W-r)){
    cout << "No\n";
    return 0;
  }
  if((y < r) || (y > H-r)){
    cout << "No\n";
    return 0;
  }

  cout << "Yes\n";
}

  

Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int e,y;
 int ans=0;
  cin>>e>>y;
  if(e==0){
    if(y<=1911){
      cout<<"M";
      ans=y-1867;
    }
    else if(y<=1925){
      cout<<"T";
      ans=y-1911;
    }
     else if(y<=1988){
      cout<<"S";
      ans=y-1925;
    }
     else{
      cout<<"H";
      ans=y-1988;
    }
    cout<<ans<<"\n";
  }
  else{
    if(e==1){
      ans=1867+y;
    }
    else if(e==2){
      ans=1911+y;
    }
    else if(e==3){
      ans=1925+y;
    }
    else{
      ans=1988+y;
    }
    cout<<ans<<"\n";
  }

  return 0;
}




Measured memory_bytes: 3184
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <utility>

namespace n91 {

void main_() {
  const u32 n = scan<u32>();
  std::cout << n * n * n << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int R,G,B,N;
    cin>>R>>G>>B>>N;
    int ans=0;
    for(int r=0;r*R<=N;r++){
        for(int g=0;g*G<=N;g++){
            if (N>=r*R+g*G){
                int b=(N-r*R-g*G)/B;
                if (r*R+g*G+b*B==N){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}


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

int main() {
  int i, j;
  int sum;
  int x;

  cin >> i;
  cin >> j;

  sum = (2 * i) + (2 * j);
  x = i * j;
  cout << x << " " << sum << endl;

  return  0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 1000000000;

int main() {
  int N; cin >> N;
  vector<int> T(N);
  rep(i, N) {
    cin >> T[i];
  }
  int M; cin >> M;
  vector<pair<int, int>> px;
  rep(i, M) {
    int p, x; cin >> p >> x;
    px.push_back(make_pair(p, x));
  }
  for (auto p : px) {
    int sum = 0;
    int idx = p.first - 1;
    rep(i, N) {
      if (i == idx) {
        sum += p.second;
      }
      else {
        sum += T[i];
      }
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<string>
#include<set>
#include<string>
#include<climits>
using namespace std;



static string s;
static int flag;
static int op[2] = { 1, -1 };
void dfs(int sum, int index, string str,string t)
{
	if (flag) return;
	if (index >= str.length())
	{
		if (sum == 7)
		{
			flag = true;
			cout << t << "=7" << endl;
		}
		return;
	}

	
	for (int j = 0; j < 2; j++)
	{
		int x = op[j] * (str[index] - '0');
		t += (j == 0 ? "+" : "-");
		t += str[index];
		dfs(sum + x, index + 1, str, t);
		t.pop_back();
		t.pop_back();
	}
	

}



int main()
{
	while (cin >> s)
	{
		flag = false;
		int f = s[0] - '0';
		string t = "";
		t += s[0];
		dfs(f, 1, s, t);
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define ll long long
#define mod 1000000007ll
ll fac[2000010],inv[2000010];
int x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6;
inline ll ksm(ll a,ll b)
{ll res=1ll,tp=a;
while (b)
{if (b&1ll) {res*=tp;res%=mod;}
tp*=tp;tp%=mod;b>>=1ll;
}
return res;
}
inline void prec()
{int i;
fac[0]=1ll;
for (i=1;i<=2000005;i++) fac[i]=fac[i-1]*((ll)(i))%mod;
inv[2000005]=ksm(fac[2000005],mod-2ll);
for (i=2000004;i>=1;i--) inv[i]=inv[i+1]*((ll)(i+1))%mod;
}
inline ll f(int a,int b)
{return (((fac[a+b]*inv[a])%mod)*inv[b])%mod;}
inline ll cal(int x1,int x2,int y1,int y2)
{return ((f(x2+1,y2+1)-f(x2+1,y1)-f(x1,y2+1)+f(x1,y1))%mod+mod)%mod;}
int main (){
	int i;
	scanf ("%d%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5,&x6);
	scanf ("%d%d%d%d%d%d",&y1,&y2,&y3,&y4,&y5,&y6);
	prec();ll ans=0;
	for (i=x3;i<=x4;i++)
	{ans+=((((mod-((ll)y3+i))*cal(i-x2,i-x1,y3-y2-1,y3-y1-1))%mod)*cal(x5-i,x6-i,y5-y3,y6-y3))%mod;
	if (ans>=mod) ans-=mod;
	}//(i,y3-1)-->(i,y3)
	for (i=x3;i<=x4;i++)
	{ans+=((((y4+i+1)*cal(i-x2,i-x1,y4-y2,y4-y1))%mod)*cal(x5-i,x6-i,y5-y4-1,y6-y4-1))%mod;
	if (ans>=mod) ans-=mod;
	}//(i,y4)-->(i,y4+1)
	for (i=y3;i<=y4;i++)
	{ans+=((((mod-((ll)x3+i))*cal(x3-x2-1,x3-x1-1,i-y2,i-y1))%mod)*cal(x5-x3,x6-x3,y5-i,y6-i))%mod;
	if (ans>=mod) ans-=mod;
	}//(x3-1,i)-->(x3,i)
	for (i=y3;i<=y4;i++)
	{ans+=((((x4+i+1)*cal(x4-x2,x4-x1,i-y2,i-y1))%mod)*cal(x5-x4-1,x6-x4-1,y5-i,y6-i))%mod;
	if (ans>=mod) ans-=mod;
	}//(x4,i)-->(x4+1,i)
	printf ("%lld\n",ans);
	return 0;
}
	

Measured memory_bytes: 31360
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vi a(n);
    rep(i,0,n)cin>>a[i];
    int q;
    cin>>q;  ;
    vi b(q);
    rep(i,0,q)cin>>b[i];
    sort(b.begin(),b.end());
    sort(a.begin(),a.end());
    int ai=0;;
    int bi=0;
    int cnt=0;
    while(bi<q){
        while(a[ai]<b[bi])ai++;
        if(ai<n&&bi<q&&a[ai]==b[bi])cnt++;
        bi++;
    }
    cout<<cnt<<endl;
    return 0;
}





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

#define MOD 1000000007

using namespace std;

int main() {
	int n, m; scanf("%d %d", &n, &m);
	char grid[n][m];

	for(int i=0; i<n; i++) scanf("%s", grid[i]);

	int dp[n][m];
	dp[0][0] = 1;

	for(int i=0; i<n; i++) {
		for(int j=0; j<m; j++) {
			if(i == 0 && j == 0)
				continue;
			if(grid[i][j] == '#') {
				dp[i][j] = 0;
				continue;
			}

			dp[i][j] = i > 0 ? dp[i-1][j] : 0;
			dp[i][j] = (dp[i][j] + (j > 0 ? dp[i][j-1] : 0)) % MOD;
		}
	}

	printf("%d\n", dp[n-1][m-1]);

	return 0;
}

Measured memory_bytes: 5120
//daddy's back in town, back to rolling the damn hash yoooo babeeeeees//
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define double long double
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
const ll mod = 1000000007;
int a[4];

int32_t main(){
	ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin>>a[1]>>a[2]>>a[3];
    sort(a+1, a+4);
    if(a[1]==a[2] && a[1]!=a[3]) cout<<"Yes";
    else if(a[2]==a[3] && a[1]!=a[2]) cout<<"Yes";
    else cout<<"No";
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

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

	bool b[x+1];
	fill(b, b+x+1, false);
	b[0]=true;
	for(int i=0; i<x; i++){
		for(int j=100; j<=105; j++){
			if(i+j<=x) b[i+j]|=b[i];
		}
	}

	cout << b[x] << endl;
	return 0;
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	// Code for A - Poisonous Cookies
	var A, B, C int
	fmt.Scanf("%d %d %d", &A, &B, &C)

	if A+B >= C {
		fmt.Println(B + C)
	} else {
		fmt.Println(A + 2*B + 1)
	}
}


Measured memory_bytes: 1832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b)
{
    if (b == 0)
    {
        return a;
    }
    return gcd(b, a % b);
}

ll N;
vi A;

int main()
{
    cin >> N;
    A = vi(N);
    REP(i, N)
    {
        cin >> A[i];
    }

    ll ans = 0;
    REP(i, N)
    {
        ans = gcd(ans, A[i]);
    }

    OUT(ans);
}

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

using namespace std;

typedef long long int64;
const int64 mod = 1e9 + 7;

int main()
{
  int N, M;

  int64 fact[100002];
  fact[0] = 1;
  for(int i = 1; i < 100002; i++) {
    (fact[i] = fact[i - 1] * i) %= mod;
  }

  cin >> N >> M;
  if(abs(N - M) >= 2) {
    cout << 0 << endl;
  } else if(abs(N - M) == 1) {
    cout << fact[N] * fact[M] % mod << endl;
  } else {
    cout << fact[N] * fact[M] % mod * 2 % mod << endl;
  }
}


Measured memory_bytes: 1024
# 数え上げで制約が 2 乗っぽいのでどうせ dp だろという気持ちになる
# なんで入力が数字で与えられるのかを考えるとちょっと視界が開ける

# よく考えると、できる列の制約は
# 「赤い/青いボールはできる列の i 個目までに A[i]/B[i] 個使える」
# と表せることがわかる
# これに気付けばあとは
#     dp[i][j] := i 個目まで並べたとき赤いボールを j 個使う場合の数
# とした dp が自然と思いつく

from itertools import accumulate
import numpy as np

def main():
    mod = 998244353
    B = list(map(int, input()))
    N = len(B)
    A = [2-b for b in B] + [0]*N
    B += [0] * N
    a = b = 0
    for i in range(2*N):
        b += B[i]
        if b > 0:
            b -= 1
            B[i] = 1
        a += A[i]
        if a > 0:
            a -= 1
            A[i] = 1

    A = list(accumulate(A))
    B = list(accumulate(B))

    dp = np.zeros((2*N+1, 2*N+1), dtype=np.int64)
    dp[0, 0] = 1
    for i, (a, b) in enumerate(zip(A, B), 1):
        dp[i, :] = dp[i-1, :]
        dp[i, 1:] = (dp[i, 1:] + dp[i-1, :-1]) % mod
        dp[i, :i-b] = 0
        dp[i, a+1:] = 0

    print(dp[2*N].sum() % mod)

main()


Measured memory_bytes: 145712
def knapsack_weight(i,single=True):
    """
    重さが小さい時のナップサックDP
    :param single: True = 重複なし
    """
    """ dp[weight <= W] = 重さ上限を固定した時の最大価値 """
    dp_min = -float("inf")  # 総和価値の最小値
    dp = [dp_min] * (W + 1)

    for item in range(N):
        if single:
            S = range(W, weight_list[item] - 1, -1)
        else:
            S = range(weight_list[item], W + 1)
        for weight in S:
            if weight==1:
                dp[weight] = max2(price_list[i][item], dp[weight])
            else:
                dp[weight] = max2(dp[weight], dp[weight - weight_list[item]] + price_list[i][item])
    return dp[W]

import sys
input = sys.stdin.readline

def max2(x, y): return x if x > y else y
def min2(x, y): return x if x < y else y

N, W = map(int, input().split())                                # N: 品物の種類 W: 重量制限                       # N: 品物の種類 W: 重量制限 K: 個数制限

price_list = [[] for _ in range(8)]
weight_list = []
for _ in range(N):
    """ price と weight が逆転して入力されている場合有り """
    x,y,z = map(int, input().split())
    price_list[0].append(x+y+z)
    price_list[1].append(-x+y+z)
    price_list[2].append(x-y+z)
    price_list[3].append(-x-y+z)
    price_list[4].append(x+y-z)
    price_list[5].append(-x+y-z)
    price_list[6].append(x-y-z)
    price_list[7].append(-x-y-z)
weight_list = [1]*N
res = 0
for i in range(8):
    res = max(knapsack_weight(i,single=True),res)
print(res)

Measured memory_bytes: 69216
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		int indA = str.indexOf('A');
		int indZ = str.lastIndexOf('Z');
		System.out.println(indZ-indA + 1);
	}
}


Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod_;
        a = a * a % mod_;
        n >>= 1;
    }
    return res;
}

// ll mod = 998244353;
ll mod = 1e9 + 7;
vector<ll> fac(1e6 + 1, 1), inv(1e6 + 1, 1), finv(1e6 + 1, 1);
ll fac_init() {
    // combination init
    for (ll i = 1; i < 1e6+1 + 1; i++) fac[i] = fac[i - 1] * i % mod;
    finv[0] = modpow(fac[fac.end() - fac.begin() - 1], mod - 2, mod);
    repe(i, 1, 1e6 + 1) finv[i] = finv[i - 1] * (ll)(1e6 - i + 1) % mod;
    reverse(all(finv));

    //inv init
    repe(i, 1, 1e6 + 1) inv[i] = modpow(i, mod - 2, mod);
}

ll perm(ll a, ll b) { return fac[a] * finv[a - b] % mod; }

ll comb(ll a, ll b) { return fac[a] * finv[b] % mod * finv[a - b] % mod; }

int main() {
    init();
    ll N, M, K;
    cin >> N >> M >> K;
    ll S = N * M;
    fac_init();
    ll ans = 0;
    vl sum(S + 1, 0);
    rep(i,S)
        sum[i + 1] = sum[i] + i + 1;

    ll C = comb(S - 2, K - 2);
    rep(i,N)rep(j,M){
        ll tmp = 0;
        ll l, r;
        // 探索点の右で縦にわって２つの四角形の累積和を考える, l=探索点を含む列のマンハッタン距離, r=探索点の右隣
        l = sum[i] + sum[N - i - 1];
        r = l + N;
        l = (j + 1) * l % mod + N * (j + 1) * j % mod * inv[2] % mod;
        r = (M - j - 1) * r % mod + N * (M - j - 1) * (M - j - 2) % mod * inv[2] % mod;
        ans = (ans + l * C % mod + r * C % mod) % mod;
    }
    ans = ans * inv[2] % mod;
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

int main() {
    int n, p;
    cin >> n >> p;
    ll ans = 1;
    int odd = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        odd += a%2;
        ans *= 2;
    }
    if (odd == 0) {
        if (p == 0) {
            cout << ans << endl;
        } else {
            cout << 0 << endl;
        }
    } else {
        cout << ans / 2 << endl;
    }
}



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

struct Node
{
	int a;
	int b;
}t[200001];

int cmp(const Node &x,const Node &y)
{
	return x.b<y.b;
}

int main()
{
	int n,i,sum;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&t[i].a,&t[i].b);
	}
	sort(t,t+n,cmp);
	sum=0;
	for(i=0;i<n;i++)
	{
		sum+=t[i].a;
		if(sum>t[i].b)
		{
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int euc(int a,int b){
    int tmp;
     if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 int r;
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  
  return b;

}

int main()
{
    long long a,b,n,m,k,i=1,j,l,ans=-1;
    char s[100001],t[100001];
    scanf("%d%d",&n,&m);
    scanf("%s",s);
    scanf("%s",t);
    k=euc(n,m);
    ans=n/k*m;
    for(i=0;i<k;i++){
        if(s[n*i/k]!=t[m*i/k]){
            ans=-1;
        }
    }
       printf("%lld",ans);
    
    return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

/*
Node treeMinimum(Node x){
  

}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z==NIL){
    return;
  }
  if(z->left!=NIL){
    treeDelete(z->left);
  }
  if(z->right!=NIL){
    treeDelete(z->right);
  }
  free(z);
}
*/
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
    if(y->key>z->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }
}
void inorder(Node u){
  if(u==NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    /*
      if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else
    */ if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } /*else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
    */
  }
  return 0;
}




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

int main() {
  int X, A, B;
  cin >> X >> A >> B;
  if(A - B >= 0)
    cout << "delicious" << endl;
  else if(B - A <= X)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;
}

Measured memory_bytes: 256
#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;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int n;cin>>n;
	cout<<(n+1)/2<<endl;
}

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

int main()
{
	int a = 0, b = 0;
	cin >> a >> b ;
	while(a!=0||b!=0){

		for (int j = 0; j < a; j++) {
			for (int i = 0; i < b; i++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
		cin >> a >> b;
	}



	return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  vector<int> c(N);
  for (int i = 0; i< N; i++) {
    cin >> v.at(i);
  }
  for (int i = 0; i< N; i++) {
    cin >> c.at(i);
  }
  int count = 0;
  for (int i = 0; i <N; i++) {
    int a = v.at(i) - c.at(i);
    if (a > 0) {
      count += a;
    }
  }
  cout << count <<endl;
}

Measured memory_bytes: 256