akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

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

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n, s = 0;
  while (cin >> n) s += n;
  cout << s << endl;
}

Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;

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

	if (N < 1000)
		cout << "ABC" << endl;
	else
		cout << "ABD" << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x[5];
int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	x[a] = 1;
	x[b] = 1;
	for (int i = 1; i <= 3; i++) {
		if (x[i] == 0) {
			printf("%d\n", i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int op[8][3]={
    1,1,1,
    1,1,-1,
    1,-1,1,
    1,-1,-1,
    -1,1,1,
    -1,1,-1,
    -1,-1,1,
    -1,-1,-1
};
string s;
int a[4];
int main() {
   cin >> s;
   for (int i=0; i<4; i++) a[i]=s[i]-48;
   int i=0;
   while (true) {
       if (a[0]+op[i][0]*a[1]+op[i][1]*a[2]+op[i][2]*a[3]==7) {
           cout << a[0] << 
           (op[i][0]==-1 ? '-' : '+') << a[1] <<
           (op[i][1]==-1 ? '-' : '+') << a[2] <<
           (op[i][2]==-1 ? '-' : '+') << a[3] <<
           "=7";
           
           return 0;
       }
       i++;
   }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,X,Y,ans;
    cin >> A >> B >> C >> X >> Y;
    if(2*C >= A + B) ans = A*X + B*Y;
    else if(X >= Y){
        if(2*C >= A) ans = 2*C*Y + A*(X - Y);
        else  ans = 2*C*X;
    }else if (X < Y){
        if(2*C >= B) ans = 2*C*X + B*(Y - X);
        else  ans = 2*C*Y;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
S = input().strip()

gp = []
prev = S[0]
cur_gp_l = 0
for i in range(1, len(S)):
	cur = S[i]
	if prev == "R" and cur == "L":
		gp.append([i - 1, cur_gp_l])
	elif prev == "L" and cur == "R":
		gp[-1].append(i - 1)
		cur_gp_l = i
	prev = cur
gp[-1].append(len(S) - 1)

counts = [0] * len(S)
for c, l, r in gp:
	even = 0
	odd = 0
	
	for i in range(l, r + 1):
		if i % 2 == 0:
			even += 1
		else:
			odd += 1
	
	if c % 2 == 0:
		counts[c] += even
		counts[c + 1] += odd
	else:
		counts[c] += odd
		counts[c + 1] += even

print(" ".join([str(count) for count in counts]))


Measured memory_bytes: 21936
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

long long n;

bool read() {
  if (scanf("%lld", &n) < 1) {
    return false;
  }
  return true;
}

int cur;

vector<int> get(long long n) {
  if (n == 1) {
    vector<int> ans = {cur, cur};
    cur++;
    return ans;
  }
  if (n & 1) {
    auto ans = get(n >> 1);
    int k = sz(ans) / 2;
    ans.insert(ans.begin() + k, cur);
    ans.push_back(cur);
    cur++;
    return ans;
  }
  auto ans = get(n - 1);
  int k = sz(ans) / 2;
  ans.insert(ans.begin() + k, cur);
  ans.insert(ans.begin() + k, cur);
  cur++;
  return ans;
}

void solve() {
  cur = 1;
  vector<int> ans = get(n);
  printf("%d\n", sz(ans));
  for (int i = 0; i < sz(ans); i++) {
    printf("%d ", ans[i]);
  }
  printf("\n");
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vl a(5);
	rep(i,5){cin>>a[i];chmax(a[i],40ll);}
	puta(sum(a)/5);
	return 0;
}


Measured memory_bytes: 3192
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    h,w,a,b=map(int,input().split())
    S=[]
    for i in range(b):
        S.append("1"*a+"0"*(w-a))
    for i in range(h-b):
        S.append("0"*a+"1"*(w-a))   
    for i in range(h):
        print(S[i])

if __name__=='__main__':
    main()

Measured memory_bytes: 4980
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

long calc_gcd(long a, long b) { while (true) if (a) b %= a, swap(a, b); else return b; }
long calc_lcm(long a, long b) { return a * b / calc_gcd(a, b); }

void solve() {
  long A, B, C, D;
  cin >> A >> B >> C >> D;

  long result = B - A + 1;
  result -= (B / C) - ((A-1) / C);
  result -= (B / D) - ((A-1) / D);

  long lcm = calc_lcm(C, D);
  result += (B / lcm) - ((A-1) / lcm);

  cout << result << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int n,k;
int main()
{
	int temp;
	scanf("%d%d",&n,&k);
	if(n==k) printf("1");
	else
	{
		k--;
		n--;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&temp);
		}
		if(n%k==0)
		{
			printf("%d",n/k);
		}
		else
		{
			printf("%d",n/k+1);
		}
	}
}

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

#define F first
#define S second
const long long mod = 1000000007;

int N, A[1<<20], X, K;

int main() {
    //freopen("input.in","r",stdin);    
    cin >> N >> K;
    for(int i = 0;i < N;i++) {
        cin >> X;
        A[X]++;
    }
    vector<int> B;
    for(int i = 1;i <= N;i++) {
        if(A[i] > 0) {
            B.push_back(A[i]);
        }
    }
    sort(B.begin(), B.end());
    if(B.size() <= K) {
        cout << 0 << endl;
        return 0;
    }
    long long ans = 0;
    for(int i = 0;i < B.size()-K;i++) {
        ans += B[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<int> a(N);
  for (int i = 0; i<N; i++) cin >> a[i];
  int sum = 0;  
  for(int i= 0; i< N; i++)sum += a[i];
  int count=0;
  for(int i=0;i<N;i++){
    if (a[i]*4*M>=sum){
      count++;
    }
  }
  if(count>=M) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
a = int(input())
b = int(input())
c = int(input())
x = int(input())
counter = 0
for i in range(a + 1):
  for j in range(b + 1):
    for k in range(c + 1):
      if 500 * i + 100 * j + 50 * k == x:
        counter += 1
        
print(counter)


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int main() {
	cin.sync_with_stdio(false);
	int A, B;
	cin >> A >> B;
	char c[100][100];
	rep(i, 100) {
		rep(j, 50)c[i][j] = '#';
		reps(j, 50, 100)c[i][j] = '.';
	}
	A--; B--;
	rep(i, 100) {
		if (i % 2 != 0)continue;
		rep(j, 50) {
			if (A > 0 && j % 2 == 0) {
				c[i][j] = '.';
				A--;
			}
		}
		reps(j, 50, 100) {
			if (B > 0 && j % 2 == 1) {
				c[i][j] = '#';
				B--;
			}
		}
	}
	cout << 100 << " " << 100 << endl;;
	rep(i, 100) {
		rep(j, 100)cout << c[i][j];
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = [ list(map(int, input().split())) for _ in range(2)]
    print(problem087c(n, a))

def problem087c(n, a):
    dp = [ [0 for _ in range(n)] for _ in range(2)]
    dp[0][0] = a[0][0]
    dp[1][0] = dp[0][0] + a[1][0]
    for i in range(n - 1):
        dp[0][i + 1] += dp[0][i] + a[0][i + 1]
        dp[1][i + 1] = max([dp[1][i] + a[1][i + 1], dp[0][i + 1] + a[1][i + 1]])
    return max([dp[0][n - 1], dp[1][n - 1]])
main()

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

int main(){
    long long n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);
    long long d = n/(a+b);
    long long ans = d*a;
    ans += min(a, (n%(a+b)));
    printf("%lld\n", ans);
}

Measured memory_bytes: 256
s = list(input())
if s[0] == 'A' and s[2:-1].count('C') == 1:
    s = s[1:]
    s.remove('C')
    new_s = []
    for i in range(len(s)):
        new_s.append(s[i].lower())
    if s == new_s:
        print('AC')
    else:
        print('WA')
else:
    print('WA')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define si(a)       scanf("%d",&a)
#define si2(a,b)    scanf("%d%d",&a,&b)
#define sl(a)       scanf("%lld",&a)
#define sl2(a,b)    scanf("%lld%lld",&a,&b)
#define pb          push_back
#define mk          make_pair
#define loop(n)     for(int i=0; i<n; i++)
#define FOR(a,b)    for(int i=a; i<=b; i++)
#define sz          size()
#define ff          first
#define ss          second
#define mem(a,val)  memset(a, val, sizeof(a))
#define md          1000000007
#define pi          acos(-1.0)

ll a,b,c,d;

int main()
{
   ll t,n,i,j,k,l,mn=0, mx=0;
   cin>>a>>b>>c>>d;

   ll ans1=a*c;
   ll ans2=a*d;
   ll ans3=c*b;
   ll ans4=b*d;
   mx=max({ans1, ans2, ans3, ans4});
   cout<<mx<<endl;
}




Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define LD long double
#define LL long long int
#define ULL unsigned long long
#define vi vector<int>
#define mod 1000000007

int main(){
    
    int N,K;
    cin>>N>>K;
    vector<int> H(N,0);
    vector<int> A(N,0);
    for(int i=0; i<N; i++)
        cin>>H[i];
    
    A[1] = abs(H[1]-H[0]);
    
    for(int i=2; i<N; i++)
    {
        int temp = INT_MAX;
        int j = 1;
        while((i-j) >=0 && j <= K)
        {
            temp = min( (A[i-j] + abs(H[i] - H[i-j])), temp) ; 
            j++;
        }
        
        A[i] = temp;
    }
    
    cout << A[N-1] << endl;

    return 0;
}

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

using namespace std;

const int N = 1e5 + 5;
int dp[N][3];
int a[N], b[N], c[N];

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

	for(int i = 1; i <= n; i++)
		cin >> a[i] >> b[i] >> c[i];

	dp[1][0] = a[1], dp[1][1] = b[1], dp[1][2] = c[1]; 
	for(int i = 2; i <= n; i++){
		dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
	}

	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
}

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

typedef long long ll;

const int MN = 333;

int H, W;
char G[MN][MN], T[MN][MN];
int psum[MN << 1][MN][MN];
ll ans, sub;

void solve() {
    for(int i = 0; i < H + W; i++) for(int j = 0; j < MN; j++) memset(psum[i][j], 0, sizeof(psum[i][j]));
    for(int i = 0; i < H + W; i++) {
        for(int y = 0; y < H; y++) {
            int x = i - y;
            if(x < 0 || W <= x) continue;
            if(G[y][x] != '#') continue;

            for(int d = 1; d < MN; d++) {
                int ny = y - d;
                int nx = x + d;
                if(ny < 0 || W <= nx) break;
                if(G[ny][nx] != '#') continue;
                psum[i][d][y]++;
            }
        }
    }
    for(int i = 0; i < H + W; i++) for(int j = 0; j < MN; j++) for(int k = 1; k < MN; k++) psum[i][j][k] += psum[i][j][k - 1];
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(G[i][j] != '#') continue;

            for(int k = 1; k < MN; k++) {
                if(i + j - 2 * k < 0) break;
                ans += psum[i + j - 2 * k][k][i];
                if(i - k > 0) ans -= psum[i + j - 2 * k][k][ i - k - 1 ];
            }
        }
    }

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(G[i][j] != '#') continue;

            for(int k = 1; k <= max(H, W); k++) {
                if(i - k < 0 || H <= i + k || W <= j + k) break;
                if(G[i - k][j + k] == '#' && G[i + k][j + k] == '#') sub++;
            }
        }
    }
}

void Rotate() {
    for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) T[j][H - 1 - i] = G[i][j];
    for(int i = 0; i < W; i++) for(int j = 0; j < H; j++) G[i][j] = T[i][j];
    swap(H, W);
}

int main() {
    scanf("%d %d", &H, &W);

    for(int i = 0; i < H; i++) {
        scanf("\n");
        for(int j = 0; j < W; j++) {
            scanf("%c", &G[i][j]);
        }
    }
    for(int i = 0; i < 4; i++) {
        solve();
        Rotate();
    }

    printf("%lld", ans - sub);
}


Measured memory_bytes: 260608
#include<stdio.h>
 
int main(void){
int a[10000];
int n;
int i;
long s=0;
int h,l;
 
scanf("%d",&n);
 
for(i =0; i<n; i++){
scanf("%d",&a[i]);
s += a[i];
}
 
l =1000001;
h=-1000001;
 
for(i=0;i<n;i++){
if(l>a[i])l = a[i];
if(h<a[i])h = a[i];
}
 
printf("%d %d %ld\n",l, h,s);
 
return 0;
}

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

const int mod = 998244353;
const int M = 1000000;

int N;
int A[200000];
long C[M + 1];
void sub() {
  for (int i = 1; i <= M; ++i) {
    long sum = 0;
    for (int k = i; k <= M; k += i) {
      sum += C[k];
    }
    C[i] = sum % mod;
  }
  
  for (int i = 1; i <= M; ++i) {
    C[i] = C[i] * C[i] % mod;
  }
  
  for (int i = M; i >= 1; --i) {
    for (int k = 2 * i; k <= M; k += i) {
      C[i] += mod - C[k];
    }
    C[i] %= mod;
  }
}

long powmod(long b, long e) {
  if (e == 0) return 1;
  if (e % 2 == 1) return b * powmod(b, e - 1) % mod;
  long t = powmod(b, e / 2);
  return t * t % mod;
}

long inv(long n) {
  return powmod(n, mod - 2);
}

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    A[i] = a;
    C[a] += a;
    if (C[a] >= mod) C[a] -= mod;
  }
  sub();
  
  long ans = 0;
  for (int i = 1; i <= M; ++i) {
    ans += inv(i) * C[i] % mod;
  }
  ans %= mod;
  
  long sum = accumulate(A, A + N, 0l) % mod;
  ans = (ans + mod - sum) * inv(2) % mod;
  cout << ans << endl;
}

Measured memory_bytes: 8832
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;

void main() {
    int a, b, c, x, y;
    scan(a, b, c, x, y);

    int ans = min(x, y) * min(2*c, a + b);

    if (x > y) {
        ans += (x - y) * min(2*c, a);
    }
    else {
        ans += (y - x) * min(2*c, b);
    }

    writeln(ans);
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
"use strict";
const combi = function(n){
    return n*(n-1)/2
}

const main = arg => {
    const input = arg.trim().split("\n");

    const N = parseInt(input[0].split(" ")[0]);
    const A = input[1].split(" ").map(n => parseInt(n));

    let m = {}
    for(let i = 0; i<A.length; i++){
        if(!m[A[i]]) m[A[i]] = 1
        else m[A[i]]++
    }
    let orgCnt = 0
    let keys = Object.keys(m)
    for(let i = 0; i<keys.length; i++){
        orgCnt = orgCnt + combi(m[keys[i]])
    }

    let out = ""
    for(let i = 0; i<A.length; i++){
        let num = m[A[i]]
        const diff = combi(num) - combi(num-1)

        out = out + String(orgCnt-diff)+"\n"
    }
    console.log(out)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 75588
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        Integer[] arrA = new Integer[a];
        Arrays.setAll(arrA, i -> Integer.parseInt(sc.next()));
        Integer[] arrB = new Integer[b];
        Arrays.setAll(arrB, i -> Integer.parseInt(sc.next()));
        Integer[] x = new Integer[m];
        Integer[] y = new Integer[m];
        Integer[] c = new Integer[m];
        for (int i = 0; i < m; i++) {
            x[i] = Integer.parseInt(sc.next());
            y[i] = Integer.parseInt(sc.next());
            c[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        // 主処理
        int minReizouko = Arrays.stream(arrA).mapToInt(i -> i).min().getAsInt();
        int minRenji = Arrays.stream(arrB).mapToInt(i -> i).min().getAsInt();
        int result = minReizouko + minRenji;
        for (int i = 0; i < m; i++) {
            int reizouko = arrA[x[i] - 1];
            int renji = arrB[y[i] - 1];
            int sum = reizouko + renji - c[i];
            result = Math.min(sum, result);
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 101568
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Set;
import java.util.HashSet;

public class Main
{
	public static void main(String[] args)throws IOException
	{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] s = br.readLine().split(" ");
		//int[] a = new int[n];
		int temp ;
		int over = 0;
		Set<Integer> set = new HashSet<>(); 
		for(int i = 0 ; i< n ; i++)
		{
			temp = Integer.parseInt(s[i]) / 400;
			if(temp >= 8) over++;
			else
			{
				set.add(temp);
			}
		}
		temp = set.size();
		if(temp == 0) {
			temp = 1;
			over-- ;
		}
		System.out.println(temp+" "+(temp + over));
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long T[2];
  cin >> T[0] >> T[1];
  long long A[2], B[2];
  cin >> A[0] >> A[1];
  cin >> B[0] >> B[1];
  B[0] -= A[0];
  B[1] -= A[1];
  long long C[2] = {abs(T[0] * B[0]), abs(T[1] * B[1])};
  if (B[0] / abs(B[0]) == B[1] / abs(B[1])) {
    cout << 0 << endl;
  } else if (C[0] == C[1]) {
    cout << "infinity" << endl;
  } else if (C[0] > C[1]) {
    cout << 0 << endl;
  } else {
    long long dif = C[1] - C[0];
    if (C[0] % dif == 0) {
      cout << C[0] / dif * 2 << endl;
    } else {
      cout << C[0] / dif * 2 + 1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3660
h, w = map(int, input().split())

pic = [""] * h
for i in range(h):
  pic[i] = input()

row = [False] * h
col = [False] * w
for i in range(h):
  for j in range(w):
    if pic[i][j] == "#":
      row[i] = True
      col[j] = True

for i in range(h):
  if row[i] == True:
    for j in range(w):
      if col[j] == True:
        print(pic[i][j], end = "")
    print()

Measured memory_bytes: 4468
import Control.Monad
import Control.Applicative
import Data.List
import Prelude

main :: IO ()
main = do
    n <- readLn :: IO Int
    lr <- replicateM n getLine
    putStrLn $ show $ solve lr

solve :: [String] -> Int
solve [] = 1
solve (x:xs) = lcm a (solve xs)
    where a = read x :: Int

Measured memory_bytes: 1020
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> p;
typedef unsigned long long int ull;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const int INF=2e9;

int main(){
    string s;cin>>s;
    int k;cin>>k;
    int n=s.size();
    if(n<k){
      cout<<0<<endl;
      return 0;
    }
    ll dp[n+1][n+1][2];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<2;k++){
                dp[i][j][k]=0;
            }
        }
    }
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int h=0;h<2;h++){
                for(int d=0;d<=(h==1?9:(int)(s[i]-'0'));d++){
                    dp[i+1][j+(d>0?1:0)][h||(d<(int)(s[i]-'0'))]+=dp[i][j][h];
                }
            }
        }
    }
    cout<<dp[n][k][0]+dp[n][k][1]<<endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi x(n),y(n);
    rep(i,n) cin>>x[i]>>y[i];
    rep(i,n-1){
        int p1 = (abs(x[i])+abs(y[i]))%2;
        int p2 = (abs(x[i+1])+abs(y[i+1]))%2;
        if (p1!=p2){
            cout<<"-1\n";
            return 0;
        }
    }
    int p = (abs(x[0])+abs(y[0]))%2;
    int m = (p)?31:32;
    cout<<m<<"\n";
    rep(i,31){
        if (i>0) cout<<" ";
        cout<<(1ll<<(30-i));
    }
    if (p==0) cout<<" 1";
    cout<<"\n";
    rep(i,n){
        int u = x[i]+y[i]-(1-p);
        int v = x[i]-y[i]-(1-p);
        rep(i,31){
            bool b1=false,b2=false;
            if (u>0){
                b1=true;
                u-=1ll<<(30-i);
            }else{
                u+=1ll<<(30-i);
            }
            if (v>0){
                b2=true;
                v-=1ll<<(30-i);
            }else{
                v+=1ll<<(30-i);
            }
            if (b1 && b2) cout<<"R";
            if (b1 && !b2) cout<<"U";
            if (!b1 && b2) cout<<"D";
            if (!b1 && !b2) cout<<"L";
        }
        if (p==0) cout<<"R";
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e9
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q, H, W, D, L, R, K,X;
ll A;
ll B;
ll ans;
string S;
char s[52][52];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll a[502][502];
int main() {
	rep(i, 0, 502) {
		rep(j, 0, 502) {
			a[i][j] = 10;
		}
	}
	cin >> H >> W;
	rep(i, 1, H + 1) {
		rep(j, 1, W + 1) {
			cin >> a[i][j];
		}
	}
	vector<pair<pair<ll, ll>, pair<ll, ll> > >v;
	pair<ll, ll> tmp1;
	pair<ll, ll> tmp2;
	pair<pair<ll, ll>, pair<ll, ll>> tmp;
	rep(i, 1, H + 1) {
		rep(j, 1, W + 1) {
			if (i == H && j == W)break;
			if (a[i][j] % 2 == 1) {
				if (j != W) {
					tmp1.first = i;
					tmp1.second = j;
					tmp2.first = i;
					tmp2.second = j + 1;
					tmp.first = tmp1;
					tmp.second = tmp2;
					v.push_back(tmp);
					a[i][j+1]++;
				}
				else {
					tmp1.first = i;
					tmp1.second = j;
					tmp2.first = i + 1;
					tmp2.second = j;
					tmp.first = tmp1;
					tmp.second = tmp2;
					v.push_back(tmp);
					a[i+1][j]++;
				}
			}
		}
	}
	cout << v.size() << endl;
	rep(i, 0, v.size()) {
		cout << v[i].first.first << " " << v[i].first.second << " " << v[i].second.first << " " << v[i].second.second << endl;
	}
	cin >> ans;
	return 0;
}

Measured memory_bytes: 8304
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-DistinctOrNot.py
#
import collections

n = int(input())

a = i = list(map(int, input().split()))
c = collections.Counter(a)
number_of_words = len(c)

if len(a) == number_of_words:
    print("YES")
else:
    print("NO")



Measured memory_bytes: 33996
//---------- begin union_find ----------
pub struct DSU {
    p: Vec<i32>,
}
impl DSU {
    pub fn new(n: usize) -> DSU {
        DSU { p: vec![-1; n] }
    }
    pub fn init(&mut self) {
        for p in self.p.iter_mut() {
            *p = -1;
        }
    }
    pub fn root(&self, mut x: usize) -> usize {
        while self.p[x] >= 0 {
            x = self.p[x] as usize;
        }
        x
    }
    pub fn same(&self, x: usize, y: usize) -> bool {
        self.root(x) == self.root(y)
    }
    pub fn unite(&mut self, x: usize, y: usize) -> Option<(usize, usize)> {
        let mut x = self.root(x);
        let mut y = self.root(y);
        if x == y {
            return None;
        }
        if self.p[x] > self.p[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.p[x] += self.p[y];
        self.p[y] = x as i32;
        Some((x, y))
    }
    pub fn parent(&self, x: usize) -> Option<usize> {
        let p = self.p[x];
        if p >= 0 {
            Some(p as usize)
        } else {
            None
        }
    }
    pub fn get_size(&self, x: usize) -> usize {
        let r = self.root(x);
        (-self.p[r]) as usize
    }
}
//---------- end union_find ----------

use proconio::*;

#[fastout]
fn run() {
    input! {
        n: usize,
        q: usize,
        ask: [(u8, usize, usize); q],
    }
    let mut u = DSU::new(n);
    for (op, a, b) in ask {
        if op == 0 {
            u.unite(a, b);
        } else {
            let ans = u.same(a, b) as u8;
            println!("{}", ans);
        }
    }
}

fn main() {
    run();
}


Measured memory_bytes: 9616
#include <iostream>
  
int main(){
  
  int n;
  while(std::cin >> n){ 
    int *array = new int[n];
    for(int i = 0; i < n;i++){
      std::cin >> array[i];
    }
    int maxv = array[1] - array[0];
    int minj;
    if(maxv < 0){
      minj = array[1];
    }else{
      minj = array[0];
    }
    for(int j = 2; j < n;j++){
      if(minj > array[j-1]){
	minj = array[j-1];
      }
      if(maxv < array[j] - minj){
	maxv = array[j] - minj;
      }
    }
    std::cout << maxv << std::endl;
    delete[] array;
  }
  return 0;
}

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

int main() {
    double x,h;
	while(cin >> x >> h) {
    if ( x+h == 0) break; 
	printf("%.6lf\n",x*x+2*x*sqrt(h*h+x*x/4));
	}
	return 0;
}

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

int main(){
  int N,K; cin >> N >> K;
  vector<int> D;
  for(int i=0;i<K;i++){
    int d; cin >> d;
    D.push_back(d);
  }
  int ans;
  int n = N;
  while(true){
    int t = n;
    bool flag = true;
    while(t > 0 && flag){
      int s = t % 10;
      t /= 10;
      for(int c:D){
        if(s == c) flag = false;
      }
    }
    if(t == 0 && flag){
      ans = n;
      break; 
    }
    n++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
let words str =
  let len = String.length str in
  let buf = Buffer.create 10 in
  let rec loop cont = function
      i when i = len -> cont [Buffer.contents buf |> int_of_string]
    | i ->
      loop
        (match str.[i] with
         | ' ' ->
           let v = Buffer.contents buf |> int_of_string in
           Buffer.clear buf; (fun x -> cont (v::x))
         | c ->
           Buffer.add_char buf c; cont)
        (i+1)
  in loop (fun x -> x) 0

let counter = ref 0

let merge array left mid right =
  let init n p = Array.init (n+1) (fun i -> if i=n then max_int else array.(p+i)) in
  let xs = init (mid-left) left in
  let ys = init (right-mid) mid in
  let rec loop i j k =
    if k < right then
      (incr counter;
       if xs.(i) <= ys.(j) then (array.(k) <- xs.(i); loop (i+1) j (k+1))
       else (array.(k) <- ys.(j); loop i (j+1) (k+1)) )
  in loop 0 0 left

let rec msort array left right =
  if left+1 < right then
    let mid = (left+right)/2 in
    msort array left mid;
    msort array mid right;
    merge array left mid right

let () =
  let n = read_int () in
  let l = read_line () |> words |> Array.of_list in
  msort l 0 n;
  Array.iteri (fun i v -> Printf.printf (if i = n-1 then "%d\n" else "%d ") v) l;
  Printf.printf "%d\n" !counter

Measured memory_bytes: 47976
#include <cstdio>
#include <vector>
#include <array>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
using ll = long long;
using namespace std;

constexpr int mod = 1e9+7;
int main() {
    int n, m; scanf("%d%d", &n, &m);
    vector<array<ll, 2> > cur(n+1);
    vector<array<ll, 2> > prv(n+1);
    cur[0][true] = 1;
    repeat_from (i,1,n+1) cur[i][false] = 1;
    while (m --) {
        prv.swap(cur);
        repeat (i,n+1) {
            repeat (p,2) {
                cur[i][p] = 0;
            }
        }
        repeat (i,n+1) {
            repeat (p,2) {
                if (i >= 1) {
                    bool q = i == 1 ? true : p;
                    cur[i-1][q] += prv[i][p]; // RR
                    cur[i][q] += prv[i][p]; // RB
                }
                if (i <= n-1) {
                    cur[i+1][p] += prv[i][p]; // BB
                    cur[i][p] += prv[i][p]; // BR
                }
            }
        }
        cur[0][ true] += cur[0][false];
        cur[0][false] = 0;
        repeat (i,n+1) repeat (p,2) cur[i][p] %= mod;
    }
    ll result = 0;
    repeat (i,n+1) result += cur[i][true];
    result %= mod;
    printf("%lld\n", result);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
int main(void){
    stack<string> st;
    string s;
    while(cin>>s){
        if(s=="+"||s=="-"||s=="*"){
            int b=stoi(st.top());st.pop();
            int a=stoi(st.top());st.pop();
            int temp;
            if(s=="+")temp=a+b;
            if(s=="-")temp=a-b;
            if(s=="*")temp=a*b;
            st.push(to_string(temp));
        }
        else{
            st.push(s);
        }
    }
    cout<<st.top()<<endl;
    return 0;
}

Measured memory_bytes: 3232
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int main(void){
	int n;
	scanf("%d",&n);
	if(n%2 == 0){
		printf("%d",n/2-1);
	}
	else{
		printf("%d",n/2);
	}
    return 0; 
}


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

int n,k,s;

main()
{
        cin>>n>>k>>s;
        vector<int> v(n,1e9-(s==1e9));
        rep(i,k)v[i]=s;
        for(auto it : v)cout<<it<<" ";
        cout<<endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
using namespace std;
int a[200];
int b[10];
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a,a+n);
    int i;
    for(i = 0; i < n; i++)
    {
        if(a[i] < 400)
            b[1] = 1;
        else if(a[i] < 800)
            b[2] = 1;
        else if(a[i] < 1200)
            b[3] = 1;
        else if(a[i] < 1600)
            b[4] = 1;
        else if(a[i] < 2000)
            b[5] = 1;
        else if(a[i] < 2400)
            b[6] = 1;
        else if(a[i] < 2800)
            b[7] = 1;
        else if(a[i] < 3200)
            b[8] = 1;
        if(a[i] >= 3200)
            break;
    }
    int cnt = 0;
    for(int j = 0; j < 10; j++)
        if(b[j] == 1)
            cnt++;
    int sum = n-i;
    sum+=cnt;
    if(cnt == 0)
        cnt = 1;
    cout << cnt << ' ' << sum << endl;;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,m,k;
main(){
	cin>>n>>m>>k;
	bool ans=false;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if ((i*j+(n-i)*(m-j))==k) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

int k,n,d=-1;
cin>>k>>n;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++)
{
    int temp;
    if(i==0) temp=(k-a[n-1])+a[0];
    else temp=a[i]-a[i-1];
    if(temp>d) d=temp;
}

cout<<k-d<<endl;


return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

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

void solve(vi& v, int n) {
	if(n == 0) {
		rep(i,v.size()) {
			printf("%d", v[i]);
			if(i < v.size()-1) printf(" ");
			else printf("\n");
		}
		return;
	}

	int l = v.size() != 0 ? v[v.size()-1] : n;
	for(int i=min(l,n); i>=1; i--) {
		int m = n - i;
		v.push_back(i);
		solve(v, m);
		v.erase(v.end()-1);
	}
}

int main() {
	int n;
	vi v;
	while(cin >> n, n) {
		solve(v, n);
	}
}

Measured memory_bytes: 0
import math


def divisor(num):
    if num < 0:
        return 0
    elif num == 1:
        return [1, ]
    else:
        divisor_list = [1, ]
        for i in range(2, int(math.sqrt(num) + 1)):
            if num % i == 0:
                divisor_list.append(i)
        return divisor_list


n = int(input())
divisor_list = divisor(n)
minA = divisor_list[-1]
print(len(str(n//minA)))


Measured memory_bytes: 3060
n = int(input())
S = input().split()
input()
T = input().split()

cnt = 0

for key in T:
	left = 0
	right = n
	mid = 0
	while left < right:
		mid = (left + right) // 2

		if int(S[mid]) == int(key):
			cnt += 1
			break

		if int(key) < int(S[mid]):#左側にある
			right = mid
		elif int(key) > int(S[mid]):#右側にある
			left = mid + 1

print(cnt)



Measured memory_bytes: 15716
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

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

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

    int k; cin>>k;

    queue<ll> que;
    for(int i=1; i<=9; i++) que.emplace(i);
    vector<ll> ans;
    while(ans.size() < k){
        ll cur = que.front(); que.pop();
        ans.emplace_back(cur);
        int rem = cur % 10;
        for(int i=0; i<=9; i++){
            if(abs(rem - i) <= 1){
                que.emplace(cur * 10 + i);
            }
        }
    }

    cout << ans[k-1] << endl;

    return 0;
}


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

ll mod = 1E9+7;

int main() {
    int H, W; cin >> H >> W;
    char state[H][W];
    for (int i=0; i<H; i++){
        string S; cin >> S;
        for (int j=0; j<W; j++){
            state[i][j] = S[j];
        }
    }
    ll dp[H][W];
    dp[0][0] = 1;
    for (int i=1; i<H; i++){
        if (state[i][0] == '.' && dp[i-1][0] == 1){
            dp[i][0] = 1;
        }
        else{
            dp[i][0] = 0;
        }
    }
    for (int j=1; j<W; j++){
        if (state[0][j] == '.' && dp[0][j-1] == 1){
            dp[0][j] = 1;
        }
        else{
            dp[0][j] = 0;
        }
    }

    for (int i=1; i<H; i++){
        for (int j=1; j<W; j++){
            if (state[i][j] == '#'){
                dp[i][j] = 0;
            }
            else{
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
            }
        }
    }
    cout << dp[H-1][W-1] << endl;
}

Measured memory_bytes: 9088
N = int(input())
a = list(map(int, input().split()))

total = sum(a)

acc_sum = [0] * N
base = 0
for i in range(N):
    base += a[i]
    acc_sum[i] = base

diff = [abs(acc * 2 - total) for acc in acc_sum]
print(min(diff[:-1]))


Measured memory_bytes: 28956
mod = 10 ** 9 + 7

n = int(input())

A = []
for i in range(n):
    A.append(list(map(int, input().split())))


memo = [-1] * (1<<n)
memo[0] = 1


def dfs(state, c):
    if memo[state] != -1:
        return memo[state]
    r = 0
    for i in range(n):
        if state & (1<<i) and A[c][i]:
            r += dfs(state ^ (1<<i), c+1)
            r %= mod
    memo[state] = r
    return r


print(dfs((1<<n)-1, 0))

Measured memory_bytes: 62940
#include <bits/stdc++.h>
#define ll long long int
#define ld double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	int n, k, i;
	vector <int> ans;
	cin >> k >> n;
	fo(i, n, n + k)
	ans.pb(i);
	for(i = n - 1; i > n - k; i--)
	ans.pb(i);
	sort(ans.begin(), ans.end());
	for(auto x : ans)
	cout << x << ' ';
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String...args) {
        Scanner scan = new Scanner(System.in);
        int count = 0;
        boolean isPrime;
        while(scan.hasNext() ) {
           isPrime = true;
           int primeNum = scan.nextInt();
           
           switch(primeNum) {
               case 1 :
                          isPrime = true;
               break;
                case 2 :
                          isPrime = true;
               break;
               default:
               if(primeNum % 2 == 0){
                   isPrime = false;
               } else {
                   int rootNum = (int)Math.sqrt(primeNum);
                   boolean flag = true;
                   while(flag && rootNum > 1) {
                       isPrime = true;
                       if(primeNum % rootNum== 0){
                           isPrime = false;
                           flag = false;
                        }else{
                            rootNum--;
                        }
                    }
               }
            }
            if(isPrime) {
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 44564
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
 
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pii;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie();
	
	ll n, k, res = 0;
	cin >> n >> k;
	while (n) {
		res++;
		n /= k;
	}
	cout << res << '\n';
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<map>
#include<stack>
using namespace std;
const int N=15;
char str[N];
int main(){
	scanf("%s",str+1);
	int n=strlen(str+1);
	if(n&1){puts("No");return 0;}
	for(int i=1;i<=n;i++){
		if((i&1)&&(str[i]!='h')){puts("No");return 0;}
		if((!(i&1))&&(str[i]!='i')){puts("No");return 0;}
	}
	puts("Yes");
	return 0;
}
/*

*/

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

#define rep(i,a,b) for (int i = a;i < b;i++)

using namespace std;

int main() {
	long long ans = 0;
	string S;
	cin >> S;

	int N = S.size();

	rep(i, 0, (1 << (N - 1))) {

		long long ret = (long long)(S[0] - '0');
		rep(j, 0, N - 1) {
			if (i & 1 << j) {
				ans += ret;
				ret = 0;
			}
			ret = (long long)(ret * 10 + (long long)(S[j + 1] - '0'));
		}
		ans += ret;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define INF 1e9

using vi=vector<int>;
using vvi=vector<vi>;

int main(){
	int n,m,a[3];
	while(cin>>n>>m>>a[0]>>a[1]>>a[2]){
		vvi z(n,vi(n,0));
		auto e=z;
		rep(_,m){
			int p,q; cin>>p>>q;
			e[p-1][q-1]=1;
		}

		vector<vvi> d(3);
		auto f=e;
		rep(l,*max_element(a,a+3)){
			rep(p,3) if(l==a[p]-1) d[p]=f;
			auto next=z;
			rep(k,n)rep(i,n)rep(j,n){
				next[i][j]|=(f[i][k] and e[k][j]);
			}
			f=next;
		}
		
		unordered_set<int> g;
		g.insert(n-1);
		rep(t,1000){
			unordered_set<int> ng;
			rep(i,n) if(!g.count(i)){
				bool ok=1;
				rep(p,3) ok&=[=]{bool r=0; rep(j,n) r|=(g.count(j) and d[p][i][j]); return r;}();
				if(ok) ng.insert(i);
			}
			if(ng.size()==0){
				cout<<"IMPOSSIBLE"<<endl;
				break;
			} else if(ng.count(0)){
				cout<<t+1<<endl;
				break;
			}
			g.insert(all(ng));
		}
	}
	return 0;
}



Measured memory_bytes: 3264
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    int l[m], r[m];
    int l_max = 0;
    int r_min = 1000000;
    rep(i, m) {
        cin >> l[i];
        cin >> r[i];

        l_max = max(l_max, l[i]);
        r_min = min(r_min, r[i]);
    }

    int ans = r_min - l_max;

    cout << max(0, ans + 1) << endl;
}

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

ll modinv(ll a, ll m){
    ll b = m, u = 1, v = 0;
    while(b){
        ll t = a / b;
        a -= t * b; swap(a,b);
        u -= t * v; swap(u,v);
    }
    u %= m;
    if(u < 0) u += m;
    return u;
}

ll c(ll n, ll m, ll mod){
    if(m == 0) return 1;
    ll ans = 1, cnt = m;
    while(cnt > 0){
        ans *= n-cnt+1;
        ans %= mod;
        cnt--;
    }
    while(m > 0){
        ans *= modinv(m, mod);
        ans %= mod;
        m--;
    }
    return ans;
}

ll modpow(ll a, ll b, ll mod){
    ll x = 1;
    for (; b > 0; b >>= 1){
        if(b & 1) x = (ll)x * a % mod;
        a = (ll)a * a % mod;
    }
    return x;
}

const ll mod = 1e9+7;

int main(){
    int N,A,B;
    cin >> N >> A >> B;
    ll sum = modpow(2, N, mod);
    sum -= 1;
    sum %= mod;
    sum -= c(N,A,mod);
    sum %= mod;
    sum -= c(N,B,mod);
    sum %= mod;
    if(sum < 0) sum += mod;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256