akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import random
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline

INF = 10**11

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def warshall_floyd(g):
    d = g
    N = len(g)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


def slv(N, M, L, ABC, Q, ST):
    g = [[INF]*(N) for _ in range(N)]
    for i in range(N):
        g[i][i] = 0
    for a, b, c in ABC:
        if c > L:
            continue
        g[a-1][b-1] = c
        g[b-1][a-1] = c

    d = g
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    gg = [[INF]*(N) for _ in range(N)]
    for u in range(N):
        for v in range(N):
            if d[u][v] <= L:
                gg[u][v] = 1

    d = gg
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

    for s, t in ST:
        c = d[s-1][t-1]
        if c != INF:
            print(c-1)
        else:
            print(-1)


def main():
    N, M, L = read_int_n()
    ABC = [read_int_n() for _ in range(M)]
    Q = read_int()
    ST = [read_int_n() for _ in range(Q)]

    (slv(N, M, L, ABC, Q, ST))


if __name__ == '__main__':
    main()


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

#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    string S;
    cin >> S;
    if (S[2] == S[3] && S[5] == S[4])cout << "Yes";
    else cout << "No";
    return 0;
}



Measured memory_bytes: 256
N = int(input())
S = input()

total = 0

R = list()
G = list()
B = list()

for i in range(N):
    if S[i] == "R":
        R.append(i)
    elif S[i] == "G":
        G.append(i)
    else:
        B.append(i)


R_len = len(R)
G_len = len(G)
B_len = len(B)

counter1 = 0
counter2 = 0
if max(R_len, G_len, B_len) == B_len:
    for i in range(R_len):
        for j in range(G_len):
            illegal = 0
            r = R[i]
            g = G[j]

            distance = abs(r - g)
            
            if r < g:
                check1 = r - distance
                check2 = g + distance
            else:
                check1 = g - distance
                check2 = r + distance

            if check1 >= 0 and S[check1] == "B":
                illegal += 1
            if check2 < N and S[check2] == "B":
                illegal += 1
            if distance % 2 == 0 and S[(r+g)//2] == "B":
                illegal += 1
   
            total += (B_len - illegal)
elif max(R_len, G_len, B_len) == G_len:
    for i in range(R_len):
        for j in range(B_len):
            illegal = 0
            r = R[i]
            b = B[j]

            distance = abs(r - b)
            
            if r < b:
                check1 = r - distance
                check2 = b + distance
            else:
                check1 = b - distance
                check2 = r + distance

            if check1 >= 0 and S[check1] == "G":
                illegal += 1
            if check2 < N and S[check2] == "G":
                illegal += 1
            if distance % 2 == 0 and S[(r+b)//2] == "G":
                illegal += 1
                
            total += (G_len - illegal)
else:
    for i in range(B_len):
        for j in range(G_len):
            illegal = 0
            b = B[i]
            g = G[j]

            distance = abs(b - g)
            
            if b < g:
                check1 = b - distance
                check2 = g + distance
            else:
                check1 = g - distance
                check2 = b + distance

            if check1 >= 0 and S[check1] == "R":
                illegal += 1
            if check2 < N and S[check2] == "R":
                illegal += 1
            if distance % 2 == 0 and S[(b+g)//2] == "R":
                illegal += 1
                
            total += (R_len - illegal)

print(total)

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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll a, b, c, d;
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    ll tot = b - a + 1;
    tot -= b / c - (a - 1) / c;
    tot -= b / d - (a - 1) / d;
    ll g = __gcd(c, d);
    c = c * d / g;
    tot += b / c - (a - 1) / c;
    printf("%lld", tot);
    return 0;
}


Measured memory_bytes: 3768
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
	
	int n;
	int w[500];
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		
		for(int i = 0; i < n; i++){
			cin >> w[i];
		}
		
		int DP[500][500] = {};
		
		for(int i = 2; i <= n; i += 2){
			for(int j = 0; j <= n - i; j++){
				DP[j][j + i - 1] = DP[j + 1][j + i - 2];
				if((w[j] - w[j + i - 1]) * (w[j] - w[j + i - 1]) <= 1 && DP[j + 1][j + i - 2] == (i - 2) / 2){
					DP[j][j + i - 1]++;
				}
				for(int k = j + 1; k < j + i - 1; k += 2){
					DP[j][j + i - 1] = max(DP[j][j + i - 1], DP[j][k] + DP[k + 1][j + i - 1]);
				}
			}
		}
		
		if(n % 2 == 1){
			cout << max(DP[0][n - 2], DP[1][n - 1]) * 2 << endl;
		}else{
			cout << DP[0][n - 1] * 2 << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 4076
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[3001][3001],a,b,c,d,MOD=998244353;
int main(void){
    cin>>a>>b>>c>>d;
    dp[a][b]=1;
    for(ll i=a;i<=c;i++){
        for(ll j=b;j<=d;j++){
            if(i==a&&j==b)continue;
            dp[i][j]=dp[i-1][j]*j%MOD+dp[i][j-1]*i%MOD;
            dp[i][j]%=MOD;
            if(i!=a&&j!=b)dp[i][j]-=dp[i-1][j-1]*(i-1)%MOD*(j-1)%MOD;
            dp[i][j]%=MOD;
        }
    }
    //cout<<dp[2][3]<<" "<<dp[3][3]<<" "<<dp[3][2]<<endl;
    cout<<(MOD+dp[c][d])%MOD<<endl;
}


Measured memory_bytes: 73904
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,p;
    cin>>n>>p;int fl = 1;
    if(n*2==p || n*4== p) puts("Yes");

    else{

        for(int i=1; i<=n; i++){
            if((i*2)+((n-i)*4)==p ||(i*4)+((n-i)*2)==p){
                puts("Yes");
                fl=0;
                break;
            }
        }

    if(fl) puts("No");

    }
}


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

int N, A[1000];

void print(){
	for (int i=0; i<N; i++){
		if (i != 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

void insertionSort(){
	for (int i=1; i<N; i++){
		int v = A[i];
		int j;
		print();
		for (j=i-1; j>=0 && A[j]>v; j--){
			A[j+1] = A[j];
		}
		A[j+1] = v;
	}
	print();
	
}

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

	insertionSort();

	return 0;

}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(c) (c).begin(), (c).end()

int g[10][10];

int main() {
  int n, m;
  while (cin >> n >> m) {
    memset(g,0,sizeof(g));
    REP(i,m) {
      int a, b;
      cin >> a >> b;
      a--;b--;
      g[a][b] = g[b][a] = 1;
    }

    vector<int> v(n);
    iota(ALL(v), 0);
    int ans = 0;
    do {
      if (v[0] != 0) continue;
      bool ng = 0;
      REP(i,n-1) {
        if (!g[v[i]][v[i+1]]) {
          ng = 1;
          break;
        }
      }
      if (!ng) ans++;
    } while(next_permutation(ALL(v)));
    cout << ans << endl;
  }
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ll long long
#define mod 1000000007
int main(){
  int n;
  cin>>n;
  ll a[n];
  ll suff[n];
  for(int i=0;i<n;i++){
      cin>>a[i];
  }
  suff[n-1]=a[n-1];
  for(int i=n-2;i>=0;i--){
    suff[i]=(suff[i+1]+a[i])%mod;
  }
  ll ans=0;
  for(int i=0;i<n-1;i++){
    ans=(ans%mod+(a[i]*suff[i+1])%mod)%mod;
  }
  cout<<ans;
  return 0;
}

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

int main()
{
    string S, T;
    int cnt = 0;

    cin >> S >> T;

    for(int i=0; i<S.size(); i++)
    {
        if(S[i] != T[i])cnt++;
    }

    cout << cnt;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k,x,l;
  cin >> n >> k;
  for(int i=0;i < n;i++){
    cin >> x;
    if(x < k-x) l += x*2;
    else l += (k-x)*2;
  }
  cout << l << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define pf push_front
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
#define vc4d(nam,type,a,b,c,d,fix) vector<vector<vector<vector<type>>>> nam(a,vector<vector<vector<type>>>(b,vector<vector<type>>(c,vector<type>(d,fix))))
const ll oo=(1ll<<60);
ll dp[3005][4][3005]={0},val[3005][3005]={0};
int main()
{
     io;
    int T=1;
    //cin>>T;
    //for(int cas=1;cas<=T;cas++)
    while(T--)
    {
       ll r,c,k,i,j,l,n,m;
       cin>>r>>c>>k;
       for(i=1;i<=k;i++)
       {
           cin>>j>>l>>n;
           val[j][l]=n;
       }
       for(i=1;i<=r;i++)
       {
           for(j=1;j<=c;j++)
           {
               dp[i][1][j]=max(max(dp[i-1][1][j],max(dp[i-1][2][j],dp[i-1][3][j]))+val[i][j],dp[i][1][j-1]);
               dp[i][2][j]=max(dp[i][1][j-1]+val[i][j],dp[i][2][j-1]);
               dp[i][3][j]=max(dp[i][2][j-1]+val[i][j],dp[i][3][j-1]);
           }
       }
       cout<<max(dp[r][1][c],max(dp[r][2][c],dp[r][3][c]));
    }
    return 0;
}


Measured memory_bytes: 297168
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define es cout<<" "
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;

int main(void) {
    int h, w;
    cin >> h >> w;
    vector<string> s(h + 2);
    string tmp(w + 2, '#');
    s[h+1] = s[0] = tmp;
    repeat (i, h) {
        string t;
        cin >> t;
        s[i + 1] = "#" + t + "#";
    }
    
    vector<vector<int>> a(h+2, vector<int>(w+2, 0));
    vector<vector<int>> b(h+2, vector<int>(w+2, 0));
    
    repeat_from_to (i, 0, h+1) {
        repeat_from_to (j, 0, w+1) {
            if (s[i][j] == '#') {continue;}
            if (s[i][j-1] == '#') {a[i][j] = 1; continue;}
            a[i][j] = a[i][j-1] + 1;
        }
        repeat_reverse_from_to (j, w+1, 0) {
            if (s[i][j] == '#') {continue;}
            if (s[i][j+1] == '#') {continue;}
            a[i][j] = a[i][j+1];
        }
    }
    
    repeat_from_to (i, 0, w+1) {
        repeat_from_to (j, 0, h+1) {
            if (s[j][i] == '#') continue;
            if (s[j-1][i] == '#') {b[j][i] = 1; continue;}
            b[j][i] = b[j-1][i] + 1;
        }
        repeat_reverse_from_to (j, h+1, 0) {
            if (s[j][i] == '#') continue;
            if (s[j+1][i] == '#') continue;
            b[j][i] = b[j+1][i];
        }
    }
    
    int ans = 0;
    repeat_from_to (i, 1, h) repeat_from_to (j, 1, w) {
        ans = max(ans, a[i][j] + b[i][j] - 1);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 39680
a, b, c, d = map(int, input().split())

sec = 0
if (a < d and c < b):
    if (a >= c):
        if (b >= d):
            sec = d - a
        else:
            sec = b - a
    else:
        if (b >= d):
            sec = d - c
        else:
            sec = b - c

print(sec)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (int) 1e9+7
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<int>
ll xpow(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
	{
		ll k = xpow(a, b / 2);
		return k * k;
	}
	if (b % 2 != 0)
		return a * xpow(a, b - 1);
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out1.txt", "w", stdout);
#endif
	fio;
	ll x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	ll i = x / d;
	ll pres;
	if (i > k) {
		pres = x - k * d;
		cout << abs(pres) << endl;
		return 0;
	}
	pres = x - i * d;
	ll rem_moves = k - i;
	if (rem_moves % 2 == 0 )
		cout << abs(pres) << endl;
	else
		cout << min(abs(pres - d), abs(pres + d));
	return 0;
}

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

int bubbleSort(int a[], int n){
    int sw = 0;
    bool flag = true;
    for (int i=0; flag; i++){
        flag = false;
        for (int j=n-1; j>=i+1; j--){
            if (a[j] < a[j-1]){
                swap(a[j], a[j-1]);
                flag = true;
                sw++;
            }
        }
    }
    return sw;
}

int main(void){
    int i, n, sw;
    cin >> n;
    int a[n];
    for (i=0; i<n; i++) cin >> a[i];
    
    sw = bubbleSort(a, n);
    
    for (i=0; i<n; i++){
        if (i) cout << ' ';
        cout << a[i];
    }
    cout << endl;
    cout << sw << endl;
    
    return 0;
}



Measured memory_bytes: 3084
now=0
idx=-1
data=[[],[]]
cnt=0
for s in input():
    if s=='F':
        cnt+=1
    elif s=='T':
        if idx==-1:
            now+=cnt
            cnt=0
            idx=1
        elif idx==0:
            data[0].append(cnt)
            cnt=0
            idx=1
        elif idx==1:
            data[1].append(cnt)
            cnt=0
            idx=0
if idx==-1:
    now+=cnt
else:
    data[idx].append(cnt)
def solve(target,move):
    dp={0,}
    for m in move:
        dpc=dp.copy()
        dp=set()
        for k in dpc:
            dp|={k-m,k+m}
    if target in dp:
        return True
    return False
x,y=map(int,input().split())
x-=now
if solve(x,data[0]) and solve(y,data[1]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 71260
x, y = map(int,input().split())
mod = 10**9 + 7

l = 10**6+3

M = [1]  # i!のmod
m = 1
for i in range(1, l):
    m = (m * i) % mod
    M.append(m)

def inv(x, y):  # xのmod yでの逆元を返す関数
    yy = y - 2
    ans = 1
    while yy > 0:
        if yy % 2 == 1:
            ans = (ans * x) % y
        x = (x**2) % y
        yy //= 2
    return ans

# print(inv(8,13))

MI = [0] * (l-1) +[inv(M[l-1], mod)]  # i!の逆元
for i in range(l-2, -1, -1):
    MI[i] = MI[i+1] * (i+1) % mod

def C(x, y):  # コンビネーション
    ans = M[x]
    ans = (ans * MI[y]) % mod
    return (ans * MI[x-y]) % mod
ans=0
for i in range(x//2+1):
    j = x-i*2
    if j >= 0 and i+2*j == y:
        # print(i,j)
        ans = (ans + C(i+j, i))%mod
print(ans)

Measured memory_bytes: 92528
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;
const int MOD = 1e9+7;

//C++17
template<typename Type>
Type GCD(Type a,Type b){ return b ? GCD(b,a%b) : a ;}
template<typename Type>
Type LCM(Type a,Type b){ return a*b / GCD(a,b) ;}

template<typename Type>//文字列の置換/Boost:replace_all()
Type replace_str(Type str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main() {
    int n;cin >> n;
    vector<int128_t> t(n);
    rep(i,n)cin >> t[i];
    int128_t ans = t[0];
    for(int i=1;i<n;i++){
        ans = LCM(ans,t[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

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

  if(b - a > 2 && a <= k-1){
    long long c;
    if((k+1-a)%2 == 0) c = 0;
    else c = 1;
    cout << a + (b - a)*((k+1-a - c)/2)+c << endl;
  }
  else{
    cout << k+1 << endl;
  }
}


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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

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

int main(){
string S;
cin >> S;
int N = S.size();
int cnt = 0;
vector<int>ans(N, 0);
REP(j, 2){
  REP(i, N){
    if(S.at(i) == 'R') cnt++;
    else{
      ans.at(i) += cnt / 2;
      ans.at(i - 1) += (cnt + 1) / 2 ;
      cnt = 0;
    }
  }
reverse(all(S));
reverse(all(ans));
REP(i, N){
  if(S.at(i) == 'R') S.at(i) ='L';
  else S.at(i) = 'R';
}
}

REP(i, N){
  print(ans.at(i));
}
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    rep(i, N) cin >> vec[i];
    sort(rALL(vec));
    ll ans = vec[0];
    for (int i = 1; i < N - 1; ++i) {
        ans += vec[(i + 1)/2];
    }
    cout << ans << endl;
    return 0;
}

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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    ll ans = 0;
    string S;
    cin >> S;
    for(ll i = 0; i < S.size()-1; i++) {
        if(S[i] != S[i+1]) {
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
    double a, b, c, s , l , h;
    cin >> a >> b >> c;
    h=b*sin(c/180.0*M_PI);
    s=a*h/2.0;
    l=sqrt(pow(h,2.0)+pow(a-b*cos(c/180.0*M_PI),2.0))+a+b;
    printf("%5lf %5lf %5lf\n", s, l, h);
    return 0;
}

Measured memory_bytes: 1292
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort()
i = 0
ans = 0
while M > 0:
    if M >= AB[i][1]:
        ans += AB[i][0]*AB[i][1]
        M -= AB[i][1]
        i += 1
    else:
        ans += AB[i][0]*M
        break
print(ans)

Measured memory_bytes: 27756
import numpy as np
from scipy.sparse.csgraph import  dijkstra
from scipy.sparse import csr_matrix

def resolve():
    N, X, Y = map(int, input().split())
    G = np.zeros((N+1, N+1), dtype=np.int64)
    for i in range(1, N):
        G[i, i+1] += 1
        G[i+1, i] += 1
    G[X, Y] += 1
    G[Y, X] += 1

    csr = csr_matrix(G)
    dist = dijkstra(csr)

    dic = {}
    for di in dist:
        for d in di:
            if d in dic:
                dic[d] += 1
            else:
                dic[d] = 1
    for i in range(1, N):
        if i in dic:
            print(dic[i]//2)
        else:
            print(0)

if __name__ == "__main__":
    resolve()


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

int main()
{
    long long a, b, c, d, tmp_a, tmp_b, tmp_z, count=0, x=0, tmp, r=0;
    cin >> a >> b >> c >> d;
    tmp_a = (b / c) - ((a-1) / c);
    tmp_b = (b / d) - ((a-1) / d);

    x = c*d;
    if (c < d)
    {
        tmp = c;
        c = d;
        d = tmp;
    }
    r = c % d;
    
    while (r != 0)
    {
        c = d;
        d = r;
        r = c%d;
    }
    tmp_z = (b / (x/d)) - ((a -1) / (x/d));

    //cout << tmp_a << " " << tmp_b <<" "<<tmp_z<< endl;
    cout << (b - a+1) - tmp_a - tmp_b + tmp_z << endl;    

}

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

int main()
{
  int n,m,X,Y;
  cin >> n >> m >> X >> Y;
  
  int x[n],y[m];
  rep(i,n) cin >> x[i];
  rep(i,m) cin >> y[i];
  
  int flag = 0;
  for(int z = X+1; z <= Y; z++){
    rep(i,n){
      if(z <= x[i]){
        flag = 1;
        break;
      }//if
    }//rep
    rep(i,m){
      if(z > y[i]){
        flag = 1;
        break;
      }//if
    }//rep
    
    if(flag == 0){
      cout << "No War" << endl;
      return 0;
    }
    flag = 0;
  }//for
  
  cout << "War" << endl;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(void)
{
    int n,a[10]={0},i,b,j;
    while(scanf("%d",&n)!=EOF){
        if(n==0)break;
        for(i=0;i<n;i++){
            scanf("%d",&b);
            a[b]++;
        }
        for(i=0;i<10;i++){
            for(j=0;j<a[i];j++){
                printf("*");
            }
            if(a[i]==0)printf("-");
            printf("\n");
        }
        for(i=0;i<10;i++){
            a[i]=0;
        }
    }
    return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
 
#define fst() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define f(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef long double ld;

ll a[200005];
ll sum[200005];

int solve(int start,int idx,int end)
{
  ll fisum=sum[idx-1]-sum[start]+a[start];
  ll sesum=sum[end-1]-sum[idx]+a[idx];
  ll idx1=idx+1;
  ll fisum1=sum[idx1-1]-sum[start]+a[start];
  ll sesum1=sum[end-1]-sum[idx1]+a[idx1];
  //printf("LOL %lld %lld %lld %lld %lld\n",fisum,sesum,idx1,fisum1,sesum1);
  while(idx1<end && abs(fisum-sesum)>abs(fisum1-sesum1))
  {
    idx1++;
    fisum=fisum1;
    sesum=sesum1;
    fisum1=sum[idx1-1]-sum[start]+a[start];
    sesum1=sum[end-1]-sum[idx1]+a[idx1];
  }
  return idx1-1;
}
int main()
{ 
  fst();
  int n,i;
  cin>>n;
  f(i,1,n+1)
  {
    cin>>a[i];
    sum[i]=sum[i-1]+a[i];
  }
  int mid=3,left=2,right=4;
  ll p,q,r,s,ans1,ans2,ans=1000000005;
  while(mid<=n-1)
  {
    left=solve(1,left,mid);
    right=solve(mid,right,n+1);
    p=sum[left-1]-sum[1]+a[1];
    q=sum[mid-1]-sum[left]+a[left];
    r=sum[right-1]-sum[mid]+a[mid];
    s=sum[n]-sum[right]+a[right];
    ans1=min(p,min(q,min(r,s)));
    ans2=max(p,max(q,max(r,s)));
    ans=min(ans,ans2-ans1);
    //printf("%lld %lld %lld %lld\n",p,q,r,s);
    //printf("%lld %lld %lld %lld\n",left,mid,right,ans);
    mid++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();
            string s2 = Console.ReadLine().Trim();
            int iK = int.Parse(s2);
            //// Debug入力
            //string sS = "";
            //int iK = 5;
            //StringBuilder sbTp = new StringBuilder();
            //if (true)
            //{
            //    string sTmp = "abcdefghijklmnopqrstuvwxyz";
            //    for (int j = 0; j < 26; j++) { sbTp.Append(sTmp.Substring(j, 1)); }
            //    for (int j = 0; j < 26; j++)
            //    {
            //        string s3 = sTmp.Substring(j, 1);
            //        for (int k = 0; k < 26; k++)
            //        {
            //            sbTp.Append(s3 + sTmp.Substring(k, 1));
            //        }
            //    }
            //    for (int j = 1; j < 26; j++)
            //    {
            //        string s3 = sTmp.Substring(j, 1);
            //        for (int k = 1; k < 26; k++)
            //        {
            //            s3 += sTmp.Substring(k, 1);
            //            for (int m = 0; m < 26; m++)
            //            {
            //                sbTp.Append(s3 + sTmp.Substring(m, 1));
            //            }
            //            if (sbTp.Length > 5000) { break; }
            //        }
            //        if (sbTp.Length > 5000) { break; }
            //    }
            //    sS = sbTp.ToString();
            //}

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<string> lstsS = new List<string>();
            for (int i = 1; i <= sS.Length; i++)
            {
                if (i > iK) { break; }
                for (int j = 0; j <= sS.Length - i; j++)
                {
                    lstsS.Add(sS.Substring(j, i));
                }
                lstsS = lstsS.Distinct().ToList();
                //if (lstsS.Count >= 5) { break; }
            }
            lstsS.Sort();                                   // 昇順

            // 出力
            Console.WriteLine("{0}", lstsS[iK - 1].ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


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

int count = 0;

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

    for (int i = 0; i < N; i++) {
        cin >> a;

         while(a % 2 == 0) {
             a /= 2;
             count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <map>

using namespace std;

bool comp(const vector<int> &a, const vector<int> &b){
    return (a[0] < b[0]);
}

int main() {
    int N, T;
    int c, t;
    vector<vector<int>> path;
    cin >> N >> T;

    for (int i=0; i < N; i++){
        cin >> c >> t;
        if (t <= T) path.push_back(vector<int>{c, t});
    }

    sort(path.begin(), path.end(), comp);

    if (path.size() == 0) cout << "TLE" << endl;
    else cout << path[0][0] << endl;


    return 0;
}

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

int main(){
	int a, b, n;
	while(std::cin >> a >> b){
		if(a == 0 && b == 0){ break; }
		
		std::vector<std::vector<int> > JOI(a + 1, std::vector<int>(b + 1, 0)); //JOI[a+1][b+1]
		JOI[1][1] = 1;
		std::cin >> n;
		
		//工事中の点の入力
		for(int i = 0 ; i < n ; ++i){
			int xi, yi;
			std::cin >> xi >> yi;
			JOI[xi][yi] = -1; //工事中の点は-1として表す
		}
		
		for(int y = 1 ; y <= b ; ++y){
			for(int x = 1 ; x <= a ; ++x){
				if(JOI[x][y] != -1){
					if(x != 1 && JOI[x - 1][y] != -1){
						JOI[x][y] += JOI[x - 1][y];
					}
					if(y != 1 && JOI[x][y - 1] != -1){
						JOI[x][y] += JOI[x][y - 1];
					}
				}
			}
		}
		std::cout << JOI[a][b] << std::endl;
	}
	
    return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    UnionFind(int N) : par(N),siz(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++){
             par[i] = i;
             siz[i] = 1;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        // merge technique（小を大にくっつける）
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    ll size(ll x){
        return siz[root(x)];
    }
};

signed main()
{   
    gearup;
    ll n,m;cin>>n>>m;
    vpii p;
    rep(i,m){
        int a,b;cin>>a>>b;
        a--;b--;
        p.push_back(make_pair(a,b));
    }

    ll res = 0;
    rep(i,m){
        UnionFind uf(n);
        rep(j,m){
            if(j==i)continue;
            uf.unite(p[j].first,p[j].second);
        }
        if(uf.size(0) != n)res++;
    }
    out(res);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	vector<int> a(m), b;
	vector<int> odds;
	for (int i = 0; i < m; ++i) {
		scanf("%d", &a[i]);
		if (a[i] & 1) odds.push_back(i);
	}
	if (odds.size() > 2) printf("Impossible\n");
	else {
		sort(odds.begin(), odds.end());
		if (odds.size() == 1) {
			swap(a[odds[0]], a[0]);
			b = a;
			--b[0];
			b.push_back(1);
		} else if (odds.size() == 2) {
			swap(a[odds[0]], a[0]);
			swap(a[odds[1]], a[m - 1]);
			b = a;
			--b[0];
			++b[m - 1];
		} else {
			b = a;
			--b[0];
			b.push_back(1);
		}
		for (int x : a) printf("%d ", x);
		printf("\n");
		if (b[0] == 0) b.erase(b.begin());
		printf("%d\n", b.size());
		for (int x : b) printf("%d ", x);
		printf("\n");
	}
}


Measured memory_bytes: 256
import Control.Applicative

gcd' :: Int -> Int -> Int
gcd' x y
  | x < y     = gcd' y x
  | r == 0    = y
  | otherwise = gcd' y r
  where
      r = x `mod` y

main :: IO ()
main = do
    [x, y] <- map (\n -> read n :: Int) . words <$> getLine
    print $ gcd' x y



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

int main(){
    ll n;
    cin>>n;
    ll k=n;
    ll dig=0;
    while(k>0){
        dig+=(k%10);
        k/=10;
    }
    if(n%dig==0)cout<<"Yes";else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){
	int i,j,r,g,b,n;
	cin >> r >> g >> b >> n;
	long long cnt = 0;
	for(i=0;i<=n;i++){
		for(j=0;j<=n;j++){
			if(r*i + g*j>n) break;
			if((n - r*i - g*j)%b==0){
				cnt++;
			}
		}
	}
	cout << cnt << endl;
}

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

int main(){
    int x,y;
    cin >> x >> y;
    for(int i=0; i<=x; i++){
        if(2*i + 4*(x-i) == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3628
n=int(input())
zisyo={}
count=0
for i in range(n):
    s="".join(sorted(input()))#間を開けないでSORT
    if s in zisyo:
        zisyo[s]+=1
        count+=zisyo[s]
    else:
        zisyo[s]=0
print(count)

Measured memory_bytes: 17852
#include<stdio.h>
int J(int n) {
	for (int i = 3; i < n; i += 2) {
		if (n % i == 0) {
			return J(n + 2);
		}
	}
	return n;
}
int main() {
	int x, ans;
	scanf("%d", &x);
	if (x == 2) {
		ans = 2;
	}
	else if (x % 2 == 1) {
		ans = J(x);
	}
	else {
		ans = J(x + 1);
	}
	printf("%d", ans);
	return 0;

}


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

int main(){
  string s;
  cin >> s;
  int k=0;
  int count = 0;
  int n=s.size();
  for(int i=0;i<n;i++){
    if(s.at(i)=='B' && i>0){
      s.erase(i-1,2);
      i=i-2;
      n=n-2;
    }
    else if(s.at(0)=='B'){
      s.erase(0,1);
      n=n-1;
    }
  }
  cout << s <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>

using namespace std;

int
main() {
 
  string s;
  cin>>s;

  if (s == "Sunny")
    cout<<"Cloudy"<<endl;
  else if (s == "Cloudy")
    cout<<"Rainy"<<endl;
  else 
    cout<<"Sunny"<<endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

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

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

inline int gcd(int a, int b) { return (a%b == 0) ? b : gcd(b, a%b); }
inline int fac(int n) { return (n==0) ? 1 : n * fac(n - 1); }

int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> q[i];
    }

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        a[i] = i + 1;
    }

    int a_pos = -1, b_pos = -1;
    int n_fac = fac(n);
    for (int i = 0; i < n_fac; i++)
    {
        if (a == p)
        {
            a_pos = i;
        }
        if (a == q)
        {
            b_pos = i;
        }
        if (a_pos != -1 && b_pos != -1)
        {
            break;
        }
        else
        {
            next_permutation(a.begin(), a.end());
        }
    }

    cout << abs(a_pos - b_pos) << endl;

    return 0;
}

Measured memory_bytes: 3576
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.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;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
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)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//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;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    string S;
    string T;
    cin >> S >> T;
    int A,B;
    cin >> A >> B;
    string U;
    cin >> U;
    if(U==S){
        A-=1;
    }
    if(U==T){
        B-=1;
    }
    cout << A << " " << B << endl;
    }

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define nl '\n'
typedef long double ld;
typedef long long ll;

const int N = 1007;
bool bpGraph[N][N];

bool findBPM(int u, bool seen[], int matchR[], int n) {
    for (int v = 0; v < n; v++) {
        if (bpGraph[u][v] && !seen[v]) {
            seen[v] = true;
            if (matchR[v] < 0 || findBPM(matchR[v], seen, matchR, n)) {
                matchR[v] = u;
                return true;
            }
        }
    }
    return false;
}

int main() { _
    int n; cin >> n;
    vector<pair<int, int>> red;
    vector<pair<int, int>> black;
    forn(i, 0, n) {
        int x, y; cin >> x >> y;
        red.push_back({x, y});
    }
    forn(i, 0, n) {
        int x, y; cin >> x >> y;
        black.push_back({x, y});
    }
    
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (red[i].first < black[j].first && red[i].second < black[j].second)
                bpGraph[i][j] = true;

    int match[n];
    memset(match, -1, sizeof(match));
    int result = 0;
    for (int u = 0; u < n; u++) {
        bool seen[n];
        memset(seen, 0, sizeof(seen));
        if (findBPM(u, seen, match, n)) {
            result++;
        }
    }
    
    cout << result << nl;
}


Measured memory_bytes: 384
//テスト
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;


int main(){
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(d,vector<int>(26));
    rep(i,d){
        rep(j,26){
            cin >> s[i][j];
        }
    }
    //答え入れる配列
    vector<int> ans(d);
    //減少
    ll sum=0;
    vector<int> last(26);
    rep(i,d){
        ll nax=-INF;
        ll nax_i;
        rep(j,26){
            ll now_sum=0;
            now_sum+=s[i][j];
            int before_last = last[j];
            last[j]=i+1;
            ll minus=0;
            rep(k,26){
                minus+=c[k]*(i+1-last[k]);
            }
            now_sum-=minus;
            if(nax<now_sum){
                nax_i = j;
                nax = now_sum;
            }
            last[j]=before_last-1;
        }
        ans[i] = nax_i+1;
    }  
    rep(i,d){
        cout << ans[i] << endl;
    }
	return 0;   
}


Measured memory_bytes: 3696
L = str(input())
mod =10**9+7

n = len(L)

dp = [[0]*2 for j in range(n+1)]
dp[0][0] = 1

for i in range(n):
    for k in range(2):
        nd = int(L[i])
        for d in range(2):
            ni = i+1
            nk = k
            if k == 0:
                if d > nd:
                    continue
                elif d < nd:
                    nk = 1
                else:
                    pass
            if d == 0:
                dp[ni][nk] += dp[i][k]
                dp[ni][nk] %= mod
            else:
                dp[ni][nk] += dp[i][k]*2
                dp[ni][nk] %= mod
print((dp[n][0]+dp[n][1])%mod)


Measured memory_bytes: 54336
import bisect
A,B,Q=map(int,input().split())
inf=10**18
s=[-inf]
t=[-inf]
for i in range(A):
  s.append(int(input()))
for i in range(B):
  t.append(int(input()))
s.append(inf)
t.append(inf)

for i in range(Q):
  x=int(input())
  a,b=bisect.bisect(s,x),bisect.bisect(t,x)
  res=inf
  for j in [s[a-1],s[a]]:
    for k in [t[b-1],t[b]]:
      res=min(res,abs(j-x)+abs(k-j),abs(k-x)+abs(k-j))
  print(res)


Measured memory_bytes: 12084
#include<stdio.h>

int main(){

int a,b,c;
char op;

while(1){ 
scanf("%d %c %d",&a,&op,&b);
  if (op == '+'){
    printf("%d\n",a + b);
  }else if(op == '-'){
    printf("%d\n",a - b);
  }else if(op == '*'){
    printf("%d\n",a * b);
  }else if(op == '/'){
    printf("%d\n",a / b);
  }
  if(op == '?'){
  break;
  }
}

return 0;
}


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

ans = 0
C = [0]
Xd = [-1] * (M+1)

for i in range(N):
    if i == 0:
        x = X
    else:
        x = x**2 % M
    
    if Xd[x] > -1:
        break
    Xd[x] = i
    ans += x
    C.append(ans)

loop_len = i - Xd[x]
if loop_len > 0:
    S = C[i] - C[Xd[x]]
    loop_num = (N - i) // loop_len
    ans += loop_num * S
    m = N - loop_num * loop_len - i
    ans += C[Xd[x]+m] - C[Xd[x]]

print(ans)

Measured memory_bytes: 13632
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>


using namespace std;
using ll = long long int; 

int main(void){

    long double a, b, c;
    cin>>a>>b>>c;

    if(4*a*b<(c-b-a)*(c-b-a) && (c-b-a)>0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;

}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	int n;
	cin >> n;
	ll a[n];
	FOR(i,n) cin >> a[i];
	ll ans1=0;
	ll ans2=0;
	ll sum1=0;
	ll sum2=0;
	int i=0;
	while(i < n){
		sum1+=a[i];
		sum2+=a[i];
			if(i%2==0 && sum1 <= 0) {ans1+=1 -sum1; sum1+=1-sum1;}
			if(i%2==1 && sum1>=0) {ans1+=sum1+1; sum1-=sum1+1;}
			if(i%2==0 && sum2 >= 0) {ans2+=1 +sum2; sum2-=1+sum2;}
			if(i%2==1 && sum2<=0) {ans2+=1-sum2; sum2+=-sum2+1;}
		i++;
	}
	cout << min(ans1,ans2);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n; cin >> n;
  int ac=0, tle=0,re=0,wa=0;

  rep(i,n) {
    string s; cin >> s;
    if (s=="AC") ac++;
    if (s=="TLE") tle++;
    if (s=="RE") re++;
    if (s=="WA") wa++;
  }
  printf("AC x %d\n", ac);
  printf("WA x %d\n", wa);
  printf("TLE x %d\n", tle);
  printf("RE x %d\n", re);
  return 0;
}

Measured memory_bytes: 3720
n , t = map(int,input().split())
a = list(map(int,input().split()))
k = [0 for i in range(n)]
nowmin = a[0]
for i in range(1,n):
    k[i] = a[i] - nowmin
    nowmin = min(nowmin,a[i])

maxri = max(k)
ans = 0
for i in range(n):
    if k[i] == maxri:
        ans += 1
print(ans)

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

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

  char three = str.at(2);
  char four = str.at(3);
  
  if (three == four){
    char five = str.at(4);
  	char six = str.at(5);
	if (five == six){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  	} else{
      cout << "No" << endl;
  }
}

Measured memory_bytes: 256
require"matrix";n,m=gets.split.map &:to_i;s=n.times.map{gets.split.map(&:to_i)};p 8.times.map{|b|s.map{|w|Vector[b[2]*2-1,(b&2)-1,b[0]*2-1].dot w}.max(m).inject :+}.max||0

Measured memory_bytes: 2812
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> ds(n);  // ネタの種類t(<=n)別においしさdのリスト
    rep(i,n) {
        int t, d;
        cin >> t >> d;
        --t;
        ds[t].push_back(d);
    }

    vector<int> y0, y1;
    rep(i,n) {
        if (ds[i].size() == 0) continue;
        sort(ds[i].begin(), ds[i].end());   // 各ネタでおいしさのsort
        y1.push_back(ds[i].back());         // 各ネタで最大のおいしさをpopしy1に追加
        ds[i].pop_back();
        y0.insert(y0.end(), ds[i].begin(), ds[i].end());    // 各ネタで2番目以降のおいしさのリストをy0に追加
    }
    sort(y0.rbegin(), y0.rend());   // ネタの種類が増えないおいしさのリスト（各ネタで2番目以降）
    sort(y1.rbegin(), y1.rend());   // ネタの種類が増えるおいしさ（各ネタで最大）のリスト

    ll ans = 0;
    // int Y = max(0, k-int(y0.size()));   // Y: ネタの種類の最小値（kまで増やしながら貪欲するため）
    int Y = min(k, int(y1.size()));   // Y: ネタの種類の最大値（減らしながら貪欲するため）
    ll X = 0;
    rep(i,Y) X += y1[i];    // Y個 ネタの種類が増えるおいしさ（各ネタで最大）を大きい順に加算
    rep(i,k-Y) X += y0[i];  // k-Y個 ネタの種類が増えないおいしさを大きい順に加算
    while (1) {
        ans = max(ans, X + (ll)Y*Y);
        // if (Y >= k || Y >= y1.size()) break;    // Yをkまで増やしながら貪欲
        // X += y1[Y];     // ネタの種類が増えるおいしさ（各ネタで最大）を大きい順に1つ追加
        // X -= y0[k-Y-1]; // ネタの種類が増えない大きさを小さい順に1つ除外
        // ++Y;
        if (Y <= 0 || k-Y >= y0.size()) break;    // Yを減らしながら貪欲
        X -= y1[Y-1];     // ネタの種類が増えるおいしさ（各ネタで最大）を小さい順に1つ除外
        X += y0[k-Y]; // ネタの種類が増えない大きさを大きい順に1つ追加
        --Y;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6396