akhauriyash/Code-Regression huggingface dataset:
INF = 1<<29
def solve(jump, i)
  to = (jump == 1) ? i + 1 : i + 2
  (jump == 1 ? $m + 1 : $m).times do |j|
    cnt = (jump == 1) ? j : j + 1
    $s[i].each do |x0, d0|
      $s[to].each do |x1, d1|
        v = i == 0 ? 0 : $dp[i][j][x0] + (x0 - x1).abs * (d0 + d1)
        $dp[to][cnt][x1] = v if $dp[to][cnt][x1] > v
      end
    end
  end
end
 
loop do
  n, $m = gets.split.map(&:to_i)
  break if n == 0
  $s = [[[0, 0]], *n.times.map { gets.split.map(&:to_i)[1..-1].each_slice(2).to_a } ]
  c = $s.flatten(1).transpose[0].max
  $dp = (n+1).times.map { ($m+1).times.map { [INF] * (c+1) } }
  ($m+1).times{ |i| $dp[0][i].fill(0) }

  n.times do |i|
    solve(1, i)
    break if i == n - 1
    solve(2, i)
  end
  p [*$dp[n-1][0,$m].flatten , *$dp[n][$m].flatten].min
end

Measured memory_bytes: 213996
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/31 21:11:22
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#include <functional>
#include <numeric>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 3000 + 5, MOD = 998244353;
int qpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }   
    return res;
}

int n, s;
int a[N];
int dp[N][N];

void add(int& x, int y) {
    x += y;
    if (x >= MOD) x -= MOD;   
}

void run() {
    cin >> n >> s;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    dp[0][0] = qpow(2, n);
    int inv2 = (MOD + 1) / 2;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= s; j++) {
            if (j >= a[i]) {
                dp[i][j] = 1ll * dp[i - 1][j - a[i]] * inv2 % MOD;
            }
            dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
        }
    }
    cout << dp[n][s] << '\n';
}

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

Measured memory_bytes: 38808
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC161A

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int X, Y, Z; cin >> X >> Y >> Z;
  cout << Z << " " << X << " " << Y << endl; 
}

Measured memory_bytes: 3624
/**
 *    author:  Taichicchi
 *    created: 12.09.2020 12:01:10
 **/

#include <bits/stdc++.h>

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
    ll L, R;

    cin >> L >> R;

    ll ans;

    for (ll i = L; i <= min(R, L + 2019); ++i) {
        for (ll j = i + 1; j <= min(R, L + 2019); ++j) {
            ans = min(ans, (i * j) % 2019);
            if (ans == 0) break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3560
#include <stdio.h>
#include <math.h>

#define PI 3.14159265358

int main(void)
{
	double x, y;
	int int_x, int_y;
	int angle_sum, s, a;
	
	x = 0;
	y = 0;
	angle_sum = 90;
	
	while (1){
		scanf("%d,%d", &s, &a);
		
		if (s == 0 && a == 0){
			break;
		}
		
		x += s * cos(angle_sum * PI / 180.0);
		y += s * sin(angle_sum * PI / 180.0);
		
		angle_sum -= a;
	}
	
	int_x = x;
	int_y = y;
	
	printf("%d\n%d\n", int_x, int_y);
	
	return (0);
}

Measured memory_bytes: 604
// AOJ 2090: Repeated Subsequences
// 2017.10.9 bal4u@uu

#include <stdio.h>
#include <string.h>

char s[303], t[303];

int c[303][303]; char z[303];    // for LCS
char f[303][303];
int LCS(char *x, int m, char *y, int n)
{
	int i, j, ret, ret2;

	memset(c, 0, sizeof(c)); memset(f, 0, sizeof(f));
	for (i = 1; i <= m; i++) for (j = 1; j <= n; j++) {
		if (x[i-1] == y[j-1]) c[i][j] = c[i-1][j-1]+1, f[i][j] = 0;
		else {
			if (c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j], f[i][j] = 1;
			else                        c[i][j] = c[i][j-1], f[i][j] = -1;
		}
	}
	ret2 = ret = c[m][n]-1;
	while (ret >= 0) {
		if      (f[m][n] > 0) m--;
		else if (f[m][n] < 0) n--;
		else z[ret] = x[m-1], ret--, m--, n--;
	}
	z[ret2+1] = 0;
	return ret2+1;
}

int main()
{
	int n, m, ans, a;

	while (scanf("%s", s) && *s != '#') {
		n = strlen(s);
		for (m = n-1, ans = 0; m > ans; m--) {
			a = LCS(s, m, s+m, n-m);
			if (a > ans) { ans = a; memcpy(t, z, a+1); }
		}
		puts(t);
	}
	return 0;
}

Measured memory_bytes: 2096
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,C;
  cin>>N>>C;
  vector<vector<int>> A(C,vector<int>(C));
  for(int i=0;i<C;i++)
    for(int &j:A[i])
      cin>>j;
  vector<vector<int>> B(3,vector<int>(C,0));
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++){
      int a;
      cin>>a;
      B[(i+j)%3][a-1]++;
    }
  int ans=1000000000000000000;
  for(int i=0;i<C;i++)
    for(int j=0;j<C;j++){
      if(i==j)continue;
      for(int k=0;k<C;k++){
        if(i==k || j==k)continue;
        int cnt=0;
        for(int l=0;l<C;l++){
          if(i!=l)cnt+=B[0][l]*A[l][i];
          if(j!=l)cnt+=B[1][l]*A[l][j];
          if(k!=l)cnt+=B[2][l]*A[l][k];
        }
        ans=min(ans,cnt);
      }
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
import sys
from itertools import accumulate as acc
def main():
    s = sys.stdin.readlines()
    N, M, _ = map(int, s[0].split())
    X = [[0] * N for _ in [0] * N]
    for L, R in (map(int, e.split()) for e in s[1:M + 1]): X[L - 1][R - 1] += 1
    S = [tuple(acc(reversed(s))) for s in zip(*(acc(x) for x in X))]
    print('\n'.join(map(str, (S[q - 1][N - p] for p, q in (map(int, e.split()) for e in s[M + 1:])))))
if __name__ == '__main__':
    main()

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N), y(M);
  for(int i = 0; i < N; i++) cin >> x[i];
  for(int i = 0; i < M; i++) cin >> y[i];
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  int Zx = x[N-1]+1, Zy = y[0];
  if(X < Zx && Zy <= Y && Zx <= Zy){
    cout << "No War" <<endl;
  } else{
    cout << "War" <<endl;
  }
}


Measured memory_bytes: 3644
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repp(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define repd(i, n) for(ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

int k, l, m, n;
const int M = 1e9 + 7;


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

    int x, t;
    cin >> n >> x >> t;

    int prd = 0;
    while(n > 0) {
        n -= x;
        prd += t;
    }

    cout << prd << endl;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,k,num;
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>num;
    int ans=1;n-=k;k--;
    ans+=n/k;
    if((n%k)!=0)ans++;
    cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	int n;
	cin>>n;
	
	vi l(n);
	REP(i,n) cin>>l[i];
	sort(ALL(l));
	
	vi check(n,0);
	llong ans=0;
	REP(i,n-1)for(int j=i+2;j<n;++j){
		auto itr=lower_bound(l.begin()+i+1,l.begin()+j,l[i]+l[j]);
		auto itr2=upper_bound(l.begin()+i+1,l.begin()+j,abs(l[i]-l[j]));
		int p=itr-l.begin();
		int p2=itr2-l.begin();
		int num=itr-itr2;
		if(p2<=i and i<p) num--;
		if(num>0){
			ans+=num;
			check[i]=1;
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;


#define PI 3.141592653589793
#define MOD 1000000007

int main()
{
	IOS;
	ll a,b,c;
	cin>>a>>b>>c;
	ll k;
	cin>>k;
	while(b<=a  &&   k>0)
	{
		b*=2;
		k--;
	}
	while(c<=b  &&  k>0)
	{
		c*=2;
		k--;
	}
	if(a<b  &&   b<c)  cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a , b , c ;
  cin >> a >> b ;
  c= a * b;
  if (c % 2 == 1){
    cout << "Odd" << endl;
  }
  else if (c % 2 == 0){
    cout << "Even" << endl;  
  }
}

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

 struct Tm{
   int qans,time,ans;
 };

int main(){
  
  Tm d[N];
  while(1){
  int M,T,P,R,m,t,p,j,tans[11][N]={},ti[11][N]={};
  cin>>M>>T>>P>>R;
  if(M+T+P+R==0) break;
  for(int i=1;i<=T;i++) d[i].ans=i,d[i].time=0,d[i].qans=0;
    for(int i=0;i<R;i++){
    cin>>m>>t>>p>>j;
    if(j==0) {
      d[t].qans++;
      ti[p][t]+=m;
      tans[p][t]=1;
    }else ti[p][t]+=20;
  }
  for(int i=1;i<=T;i++)
    for(int j=1;j<=P;j++) if(tans[j][i]==1) d[i].time+=ti[j][i];
      for(int i=1;i<=T-1;i++)
    for(int j=i;j<=T;j++){
      if(d[i].qans < d[j].qans) swap(d[i],d[j]);
     else if(d[i].qans==d[j].qans && d[i].time>d[j].time) swap(d[i],d[j]);
     else if(d[i].ans<d[j].ans && d[i].qans==d[j].qans && d[i].time==d[j].time) swap(d[i].ans,d[j].ans);
    }
  
  for(int i=1;i<=T;i++){
    cout<<d[i].ans;
  if(i<T && d[i].qans==d[i+1].qans && d[i].time==d[i+1].time) cout<<"=";
  else if(i<T) cout<<",";
  }
  cout<<endl;
  }
  return 0;
}
  

Measured memory_bytes: 1348
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair 
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define rrep(i,a,b) for(int i = a; i >=b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
#define all(x) (x).begin(),(x).end()
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using ii = pair<int, int>;
using pli = pair<ll, int>;
using vi = vector<int>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using pil = pair<int,ll>;
using vvi = vector<vi>;
using vpi = vector<ii>;

const int N = 100100;
ll mod=1000000007;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int x = n%1000;
    if(x)cout<<1000 - x<<nl;
    else cout<<0<<nl;
    return 0;
}


Measured memory_bytes: 3644
#include <cstdio>
#include <stack>
#include <list>
using namespace std;

typedef struct{
    int left_edge;
    int area;
}part;

list<part> calc(list<part> parts){
    int num = parts.size() - 1;
    part tmp;
    parts.push_front(parts.back());
    parts.pop_back();
    for(int i=0;i<num;i++){
        if(parts.back().left_edge < parts.front().left_edge)
            parts.push_front(parts.back());
        else
            parts.front().area += parts.back().area;
        parts.pop_back();
    }
    return parts;
}

int main(){
    list<part> parts;
    stack<int> s;
    char str[20001];
    int i=0;
    int sum=0;
    part tmp;

    scanf("%s",str);

    while(str[i]!='\0'){
        switch(str[i]){
        case '\\':
            s.push(i);
            break;
        case '_':
            break;
        case '/':
            if(s.empty())
                break;
            tmp.left_edge = s.top();
            tmp.area = i - tmp.left_edge;
            sum += tmp.area;
            parts.push_back(tmp);
            s.pop();
            break;
        default:
            return -1;
        }
        i++;
    }

    printf("%d\n",sum);

    parts = calc(parts);

    printf("%lu",parts.size());

    while(parts.size()){
        printf(" %d", parts.front().area);
        parts.pop_front();
    }

    printf("\n");

    return 0;
}



Measured memory_bytes: 3464
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x[ohara],y,sum,pos,k,q,l,r[35][ohara];
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
unordered_map<ll,ll> mp;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    set<ll> st;
    rep(i,n)cin>>x[i],st.insert(x[i]),mp[x[i]]=i;
    cin>>l>>q;
    rep(i,n){
        auto iti=st.upper_bound(x[i]+l);
        iti--;
        pos=*iti;
        pos=mp[pos];
        r[0][i]=pos;
    }
    rrep(i,1,31){
        rep(j,n){
            r[i][j]=r[i-1][r[i-1][j]];
        }
    }
    rep(i,q){
        ll fr,to,now;
        cin>>fr>>to;
        fr--;to--;
        if(fr>to){
            tmp=fr;
            fr=to;
            to=tmp;
        }
        now=fr;
        rrrep(j,30,0){
            if(r[j][now]<to){
                now=r[j][now];
                ans+=1<<j;
            }
        }
        Cout(ans+1);
        ans=0;
    }
    return 0;
}


Measured memory_bytes: 98468
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

vector<P> result;


int sum(vector<int> vec){
  int sum = 0;
  for(int i = 0; i < vec.size(); i++){
    sum += vec[i];
  }
  return sum;
  
}

void solve(int sub, vector<int> tarou, vector<int> hanako, bool flag){
  result.clear();
  if(sub % 2 == 1){
    cout << "-1" << endl;
    return;
  }
  int a = sub / 2;
  for(int i = 0; i < tarou.size(); i++){
    for(int j = 0; j < hanako.size(); j++){
      if(flag){
        if((tarou[i] - hanako[j]) == a){
          result.push_back(P(tarou[i], hanako[j]));
        }
      }
      else{
        if((hanako[j] - tarou[i]) == a ){
          result.push_back(P(tarou[i], hanako[j]));
        }
      }
    }
  }

  if(result.size() == 0){
    cout << "-1" << endl;
    return;
  }
  
  int index = 0;
  int s = result[0].first + result[0].second;
  for(int i = 1; i < result.size(); i++){
    int tmp = result[i].first + result[i].second;
    if(s > tmp) {
      s = tmp;
      index = i;
    }
  }
  
  cout << result[index].first << " " << result[index].second << endl;
}

int main(){
  int n, m;
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    vector<int> tarou, hanako;
    for(int i = 0; i < n; i++){
      int tmp ;
      cin >> tmp;
      tarou.push_back(tmp);
    }
    for(int i = 0; i < m; i++){
      int tmp;
      cin >> tmp;
      hanako.push_back(tmp);
    }

    //cout << "(" << sum(tarou) << ", " << sum(hanako) << ")" << endl;
    int sub = abs(sum(tarou) - sum(hanako));
    bool flag = sum(tarou) > sum(hanako);
    solve(sub, tarou, hanako, flag);
  }
}

Measured memory_bytes: 3232
#include<cstdio>
int max(int x,int y)
{
return x>y?x:y;
}
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
int x=max(a,max(b,c));
printf("%d\n",a+b+c-x);
return 0;
}

Measured memory_bytes: 128
N=int(input())
D,X=map(int,input().split())
A=[int(input()) for _ in range(N)]
chocolate=X
for a in A:
    y=0
    i=0
    while True:
        y=i*a+1
        if y<=D:
            chocolate+=1
        else:
            break
        i+=1
print(chocolate)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int C,N,M,X;
C=0;
X=0;
cin>>N;
vector<string>A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);}
cin>>M;
vector<string>B(M);
  for(int j=0;j<M;j++){
    cin>>B.at(j);}
    
 for(int k=0;k<N;k++){
  X=0;
   for(int l=0;l<N;l++){
    if(A.at(k)==A.at(l)){
      X++;}
   }
   for(int m=0;m<M;m++){
    if(A.at(k)==B.at(m)){
      X--;}
   } 
   if(X>=C){
     C=X;}  
  }
if(C<=0){
  cout << 0 << endl;}
else{
  cout << C << endl;}
  
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

#define ll long long

const int N = 44;

int n;
char G[N][N];
ll dp[N][N][N];

ll solve(int l, int r, int sp) {
  if (l == sp || r == sp)
    return l == r;
  ll& rt = dp[l][r][sp];
  if (~rt)
    return rt;
  rt = 0;
  for (int x = l; x < sp; x++) {
    for (int y = sp + 1; y <= r; y++) {
      if (G[x][y] == '0')
        continue;
      for (int p = x; p < sp; p++) {
        for (int q = sp; q < y; q++) {
          rt += solve(l, p, x) * solve(p + 1, q, sp) * solve(q + 1, r, y);
        }
      }
    }
  }
  return rt;
}

int main() {
  scanf("%d", &n);
  n <<= 1;
  for (int i = 1; i <= n; i++) {
    scanf("%s", G[i] + 1);
  }
  memset(dp, -1, sizeof(dp));
  ll ans = 0;
  for (int i = 2; i <= n; i++) {
    if (G[1][i] == '1') {
      ans += solve(2, n, i);
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    int w,a,b;
    cin >> w >> a >> b;
    int aw,bw;
    aw = a+w;
    bw = b+w;
    int gap = abs(a-b);
    gap = min(gap,abs(a-bw));
    gap = min(gap,abs(aw-b));
    gap = min(gap,abs(aw-bw));
    if(abs(a-b)<=abs(a-aw)||abs(aw-bw)<=abs(b-bw)){
        gap = 0;
    }
    cout << gap << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;
#define MAXN 100010
vector<int> adj_f[MAXN];
vector<int> adj_b[MAXN];
bitset<MAXN> visited;

int32_t main(){
	ios::sync_with_stdio(0);	
	int n, m, k;
	cin >> n >> m >> k;
	for(int i=0; i<m; ++i){
		int a, b;
		cin >> a >> b;
		adj_f[a].push_back(b);
		adj_f[b].push_back(a);
	}	
	for(int i=0; i<k; ++i){
		int a, b;
		cin >> a >> b;
		adj_b[a].push_back(b);
		adj_b[b].push_back(a);
	}
	vector<int> ans(n);
	for(int x=1; x<=n; ++x){
		if(visited[x]) continue;
		set<int> gp;
		stack<int> q;
		q.push(x);
		visited[x] = true;
		gp.insert(x);
		while(not q.empty()){
			int u = q.top(); q.pop();
			for(auto v:adj_f[u]){
				if(visited[v]) continue;
				visited[v] = true;
				q.push(v);
				gp.insert(v);
			}
		}
		int tot = len(gp);
		for(auto u:gp){
			int value = tot-len(adj_f[u]);
			for(auto v:adj_b[u])
				if(gp.find(v)!=gp.end()) --value;
			ans[u-1] = value-1;
		}
	}
	for(int i=0; i<n; ++i)
		cout << ans[i] << (i==n-1 ? '\n' : ' ');
}


Measured memory_bytes: 17400
import math

def isPrime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
  
  # nの平方根まで計算する
    m = math.floor(math.sqrt(n)) + 1
    for p in range(3, m, 2):
        if n % p == 0:
            return False
    return True

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def main():
    A, B = [int(i) for i in input().split()]
    count = 0
    a = []
    prime = []
    if A > B:
        temp = A
        A = B
        B = temp
    a = make_divisors(A)
    
    for i in a:
        if isPrime(i) == True:
            prime.append(i)
    for i in prime:
        if B % i == 0:
            count += 1

    print(count)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3284
/*
  AUTHOR:SOURABH
  CREATED:29:11:19
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m2==m1)
        cout<<0;
    else
        cout<<1;
    return 0;
}














Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int X, Y;
    cin >> X >> Y;

    if (!((Y - 2 * X) >= 0 && (Y - 2 * X) % 2 == 0))
    {
        cout << "No\n";
        return 0;
    }

    if (!((4 * X - Y) >= 0 && (4 * X - Y) % 2 == 0))
    {
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";
    return 0;
}



Measured memory_bytes: 3652
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(string s;cin>>s;){
		string res;
		for(int i=0;i<s.size();){
			if(s[i]=='@'){
				res+=string(s[i+1]-'0',s[i+2]);
				i+=3;
			}
			else{
				res+=s[i];
				i++;
			}
		}
		cout<<res<<endl;
	}
	
	return 0;
}

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

template <class T>
int selectionSort(vector<T>& a) {
    int cnt = 0;
    for (int i = 0; i < a.size(); ++i) {
        T m = a[i];
        int minj = i;
        for (int j = i; j < a.size(); ++j) {
            if (a[j] >= m) continue;
            m = a[j];
            minj = j;
        }
        swap(a[i], a[minj]);
        if (i != minj) cnt++;
    }
    return cnt;
}

template<class T>
void printVector(vector<T> &a, string delimiter) {
    if (a.size() == 0) return;
    cout << a[0];
    for (int i = 1; i < a.size(); ++i) {
        cout << delimiter << a[i];
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int k = selectionSort(a);
    printVector(a, " ");
    cout << k << endl;
}



Measured memory_bytes: 3156
#!/usr/bin/env ruby

def bomb(x, y)
  return if @field[x][y] != 1
  @field[x][y] = 0

  -3.upto(3) do |i|
    next if i.zero?
    bomb(x + i, y) if (x + i) >= 0 && (x + i) < 8
    bomb(x, y + i) if (y + i) >= 0 && (y + i) < 8
  end
end

n = gets.chomp!.to_i

# skip empty line
gets

n.times do |i|
  @field = []
  8.times do |r|
    @field[r] = gets.chomp!.split('').map(&:to_i)
  end

  bomb_x = gets.chomp!.to_i
  bomb_y = gets.chomp!.to_i

  # simulate bomb
  bomb(bomb_y - 1, bomb_x - 1)

  # output result
  puts "Data #{i + 1}:"
  8.times do |r|
    puts @field[r].join('')
  end

  # skip empty-line
  gets if i + 1 != n
end

Measured memory_bytes: 7004
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  int n, T; cin >> n >> T;

  int ans = INT_MAX;

  rep(i, n) {
    int c, t; cin >> c >> t;
    if (t <= T) {
      ans = min(c, ans);
    }
  }

  if (ans == INT_MAX) {
    cout << "TLE" << endl;
  } else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
    int N,A,B,C,X;
    N =1;
    C =1;
    while(N != 0 && C != 0 ){
        int cnt = 0,lop3=0;
        cin>>N>>A>>B>>C>>X;
        if(N == 0 && C == 0 ){
            break;
        }
        int Y[N];
        for(int lop=0 ;lop< N;lop++){
            cin>>Y[lop];
        }
        for(int lop2=0 ;lop2< 10009;lop2++){
            if(Y[lop3] == X){
                cnt++;
                lop3++;
            }
            if(cnt == N){
                cout << lop2<<endl;
                break;
            }else if(lop2 == 10000){
                cout<<-1<<endl;
                break;
            }
            X = (A * X + B)%C; 
        }
    }

    return 0;
}


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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  int a, b; cin >> a >> b;
  if (a <= 0 && 0 <= b) {cout << "Zero" << endl; return 0;}
  if (a > 0) {cout << "Positive" << endl; return 0;}
  if ((a-b)%2 == 0) cout << "Negative" << endl;
  else cout << "Positive" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys

# sys.stdin = open('a1.in')


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


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


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    q, h, s, d = read_int_list()
    n = read_int()
    res = 0
    a = n % 2
    res += min([s * a, h * 2 * a, q * 4 * a])
    a = n - a
    res += min([d * a // 2, s * a, h * 2 * a, q * 4 * a])
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,n) for(int j=0;j<n;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef vector<pair<int ,int> >vepa;
typedef set<char>se;
typedef map<ll,ll> mpp;
const ll N=1e5,OO=1e14;
const int di[]={1,-1,0,0};
const int dj[]={0,0,1,-1};
ll TC,n,m,k,a,b,c,cnt,ans,sum,mx,mn,arr[N];
bool f,vis[N];
int main(){
     IOS;
     cin>>n;
     if(n>=30)
        cout<<"Yes";
     else
        cout<<"No";
go;
}


Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
using std::min;
int main(){
    int a,b,c,k;scanf("%d%d%d%d",&a,&b,&c,&k);long long ans=min(k,a);k-=a;
    if(k<=0)goto print;k-=b;
    if(k<=0)goto print;ans-=min(k,c);
    print: printf("%lld\n",ans);
}

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

int main() {
	int k, a, b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; i++ ) {
		if (i % k == 0) {
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
	return 0;
}

Measured memory_bytes: 3636
import math
n = int(input())
sosu = {2:0, 3:0, 5:0, 7:0, 11:0, 13:0, 17:0, 19:0, 23:0, 29:0, 31:0, 37:0, 41:0, 43:0, 47:0, 53:0, 59:0, 61:0, 67:0, 71:0, 73:0, 79:0, 83:0, 89:0, 97:0, 101:0, 103:0, 107:0, 109:0, 113:0, 127:0, 131:0, 137:0, 139:0, 149:0, 151:0, 157:0, 163:0, 167:0, 173:0, 179:0, 181:0, 191:0, 193:0, 197:0, 199:0, 211:0, 223:0, 227:0, 229:0, 233:0, 239:0,241:0, 251:0, 257:0, 263:0, 269:0, 271:0, 277:0, 281:0, 283:0, 293:0, 307:0, 311:0, 313:0, 317:0, 331:0, 337:0, 347:0, 349:0, 353:0, 359:0, 367:0, 373:0, 379:0, 383:0, 389:0, 397:0, 401:0, 409:0, 419:0, 421:0, 431:0, 433:0, 439:0, 443:0, 449:0, 457:0, 461:0, 463:0, 467:0, 479:0, 487:0, 491:0, 499:0, 503:0, 509:0, 521:0, 523:0, 541:0, 547:0, 557:0, 563:0, 569:0, 571:0, 577:0, 587:0, 593:0, 599:0, 601:0, 607:0, 613:0, 617:0, 619:0, 631:0, 641:0, 643:0, 647:0, 653:0, 659:0, 661:0, 673:0, 677:0, 683:0, 691:0, 701:0, 709:0, 719:0, 727:0, 733:0, 739:0, 743:0, 751:0, 757:0, 761:0, 769:0, 773:0, 787:0, 797:0, 809:0, 811:0, 821:0, 823:0, 827:0, 829:0, 839:0, 853:0, 857:0, 859:0, 863:0, 877:0, 881:0, 883:0, 887:0, 907:0, 911:0, 919:0, 929:0, 937:0, 941:0, 947:0, 953:0, 967:0, 971:0, 977:0, 983:0, 991:0, 997:0}
for i in range(2, n + 1):
    k = i
    for j in sosu:
        while k % j == 0:
            sosu[j] += 1
            k //= j
ans = 1
for i in sosu:
    ans = ans * (sosu[i] + 1) % (10**9 + 7)
print(ans)


Measured memory_bytes: 3316
import java.util.*;
import java.io.*;
public class Main {
    static InputStreamReader r;
    static int H;
    static int W;
    static int[][] maze;
    public static void main(String[] args) throws Exception {
        r = new InputStreamReader(System.in);
        H = nextInt();
        W = nextInt();

        maze = new int[H+2][W+2];
        for (int i = 0; i < H+2; i++) {
            for (int j = 0; j < W+2; j++) {
                if (i == 0 || i == H+1 || j == 0 || j == W+1) {
                    maze[i][j] = -1;
                    continue;
                }
                int c = r.read();
                if (c == 32 || c == 10 || c == -1) {
                    c = r.read();
                }
                String Sij = "" + (char)c;
                if (Sij.equals("#")) {
                    maze[i][j] = -1;
                }
            }
        }

        int max = 0;
        for (int i = 0; i < H+2; i++) {
            for (int j = 0; j < W+2; j++) {
                if (maze[i][j] != -1) {
                    max = Math.max(max, check(copy(i, j)));
                }
            }
        }

        int ans = max - 1;
        System.out.println(ans);
    }

    public static int[][] copy(int h, int w) {
        int[][] res = new int[H+2][W+2];
        for (int i = 0; i < H+2; i++) {
            for (int j = 0; j < W+2; j++) {
                res[i][j] = maze[i][j];
            }
        }
        res[h][w] = 1;
        return res;
    }

    public static int check(int[][] tmp) {
        int res = 1;
        while (true) {
            boolean update = false;
            for (int i = 0; i < H+2; i++) {
                for (int j = 0; j < W+2; j++) {
                    if (tmp[i][j] == res) {
                        if (tmp[i-1][j] == 0) {
                            tmp[i-1][j] = res + 1;
                            update = true;
                        }
                        if (tmp[i][j-1] == 0) {
                            tmp[i][j-1] = res + 1;
                            update = true;
                        }
                        if (tmp[i][j+1] == 0) {
                            tmp[i][j+1] = res + 1;
                            update = true;
                        }
                        if (tmp[i+1][j] == 0) {
                            tmp[i+1][j] = res + 1;
                            update = true;
                        } 
                    }
                }
            }
            if (update == true) {
                res++;
            } else {
                break;
            }
        }
        return res;
    }

    public static String nextString() throws Exception {
        String res = "";
        while (true) {
            int c = r.read();
            if (c == 32 || c == 10 || c == -1) {
                break;
            }
            res += (char)c;
        }
        return res;
    }

    public static int nextInt() throws Exception {
        return Integer.parseInt(nextString());
    }

    public static long nextLong() throws Exception {
        return Long.parseLong(nextString());
    }
}

Measured memory_bytes: 21588
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        A, B = map(int, input().split())
        if A < 10 and B < 10:
            print(A * B)
        else:
            print(-1)


# Run main
if __name__ == '__main__':
    AtCoder().main()


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define fori(a, n) for(ll (a) = 0; a < (n); ++a)
#define forI(a, n) for(ll (a) = 1; a <= (n); ++a)
#define pll pair<ll, ll>
#define pt pair<ll, ll>
#define x first
#define ff first
#define y second
#define ss second

const ll MAXN = 5e5 + 1;
const ll INF = 9e18;
const ll mod = 1e9 + 7;

ll n, m;

ll dp[3001][3001];
ll sm[3001][3001];

void solve(){
    string s;
    cin >> n >> s;
    dp[1][1] = 1;
    forI(i, n) sm[1][i] = 1;
    for(ll i = 2; i <= n; ++i){
        if (s[i - 2] == '<') {
            forI(j, i) dp[i][j] = sm[i - 1][j - 1];
        } else {
            forI(j, i) dp[i][j] = (sm[i - 1][i - 1] - sm[i - 1][j - 1] + mod) % mod;
        }
        forI(j, n) sm[i][j] = (sm[i][j - 1] + dp[i][j]) % mod;
    }
    cout << sm[n][n];
}

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

    //freopen("input2.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    solve();
}


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

using namespace std;
typedef long long ll;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))

const double pi=acos(-1);
const int mod=1e9+7;
const int maxn=1e4+10;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b&&a!=c)||(a==c&&b!=c)||(c==b&&b!=a))
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<bitset>
#define LL long long
#define MINF (-1000000000000000)
int N, C;
int x;
int R[32][100100];
int AA[200100];
int main() {
	std::cin >> N >> C;
	for (int i = 1; i <= N; i++) {
		int a, b, c;
		std::cin >> a >> b >> c;
		R[c][a]++;
		R[c][b]--;
	}
	for (int i = 1; i <= C; i++) {
		for (int j = 0; j <= 100010; j++) {
			if (R[i][j] == 1) {
				AA[j * 2]++;
			}
			if (R[i][j] == -1) {

				AA[j * 2 + 2]--;
			}
		}
	}
	for (int i = 1; i < 200010; i++) {
		AA[i] += AA[i - 1];
		x = std::max(x, AA[i]);
	}
	std::cout << x << std::endl;
	return 0;
}

Measured memory_bytes: 12800
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int a, b,x;
	cin >> x>>a >> b;

	if (a-b>=0) {
		cout << "delicious" << "\n";
	}
	else if (b-a<=x) {
		cout << "safe" << "\n";
	}
	else {
		cout << "dangerous" << "\n";
	}
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);

fscanf(STDIN, "%s", $S);
$str = str_split($S);

$first_W = 0;
$first_R = 0;
$R_count = array_fill(0, $N+1,0);
$W_count = array_fill(0, $N+1,0);

foreach($str as $n => $value){
    if($value === "W"){
        if($first_W === 0){
            $first_W = $n+1;
        }
        $W_count[$n+1] = $W_count[$n] + 1;
        $R_count[$n+1] = $R_count[$n];

    }else{
        if($first_R === 0){
            $first_R = $n+1;
        }
        $R_count[$n+1] = $R_count[$n] + 1;
        $W_count[$n+1] = $W_count[$n];

    }

}

if($R_count[$N] === 0 || $W_count[$N] === 0){
    echo 0;
    exit;
}
$ans = min($W_count[$N], $R_count[$N]);

$ans = min($ans, $R_count[$N]- $R_count[$R_count[$N]]);

echo $ans;

Measured memory_bytes: 41088
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

long long solve() {
  int N;
  cin >> N;

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

  vector<vector<long long>> C(N + 1, vector<long long>(63, 0));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 63; j++) {
      if (A[i] & ((long long) 1 << j)) {
        C[i+1][j] = C[i][j] + 1;
      } else {
        C[i+1][j] = C[i][j];
      }
    }
  }

  long long ans = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int k = 0; k < 63; k++) {
      long long c = C[N][k] - C[i+1][k];
      if (A[i] & ((long long) 1 << k)) {
        c = (long long) (N - i - 1) - c;
      }
      c = c % MOD;
      ans += ((((long long) 1 << k) % MOD) * c) % MOD;
      ans = ans % MOD;
    }
  }
  return ans % MOD;
}

int main() {
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 159616
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  int Tc; cin >> Tc;
  int H, M;
   
  while(Tc --) {
    scanf("%d:%d", &H, &M);
     
    double h = H*30.0 + M/2.0, m = M*6;
     
    int ang = abs(h - m);
    if(ang > 180) ang = 360 - ang;
    if(0 <= ang && ang < 30) {
      cout << "alert" << endl;
    }
    else if(90 <= ang && ang <= 180) {
      cout << "safe" << endl;
    }
    else cout << "warning" << endl;
  }
   
  return 0;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

signed main(){
	fast;
	int a,b;
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b));
}

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

#define bolt ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef long double ld;

const ld pi=3.1415926535897932384626433;
const int mod = 1000000007;
const ll inf=3e18;
// 92DTG

int main ()
{
   bolt;
   ll a,b,c,k;
   cin>>a>>b>>c>>k;
   if (k<=a)
   {
      cout<<k;
      return 0;
   }
   else if (k<=a+b)
   {
      cout<<a;
      return 0;
   }
   else
   {
      k-=a;
      k-=b;
      cout<<a-k;
      return 0;
   }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

//int dp[111111][2];
vi adj[111111];
int dp[111111][2];
void dfs(int u, int p)
{
	//vi vec; int sum=0; vi vgood; int sumgood=0; int ch=0;
	int sum=0; int cnt=0; int sumgood=0; int ch=0;
	for(int v:adj[u])
	{
		if(v==p) continue;
		dfs(v,u);ch++;
		//sumgood+=dp[v][1];
		//sum+=min(dp[v][0],dp[v][1]); vgood.pb(dp[v][1]);
		//if(dp[v][0]==0) vec.pb(min(dp[v][0],dp[v][1]));
		sum+=dp[v][0]; sumgood+=dp[v][1]; if(dp[v][0]==0) cnt++;
	}
	/*
	sort(vgood.begin(),vgood.end());
	sort(vec.begin(),vec.end());
	dp[u][0] = dp[u][1] = sum;
	if(ch==0)
	{
		dp[u][0] = 0; dp[u][1] = 1;
	}
	else if(ch==1)
	{
		dp[u][0] = sum; dp[u][1] = sumgood;
	}
	else
	{
		if(p==-1)
		{
			dp[u][1] = min(dp[u][1], sumgood - vgood.back());
		}
		dp[u][0] = min(dp[u][0], sum - vec.back());
	}
	//cerr<<u<<' '<<dp[u][0]<<' '<<dp[u][1]<<'\n';
	*/
	if(ch==0)
	{
		dp[u][0] = 0; dp[u][1] = 1;
	}
	else if(ch==1)
	{
		dp[u][0] = sum; dp[u][1] = min(sum+1,sumgood);
	}
	else
	{ 
		dp[u][0] = sum + max(cnt-1,0);
		if(p==-1) 
		{
			if(ch>=3||cnt!=1) dp[u][1] = sum + max(cnt - 1,0);
			else
			{
				dp[u][1] = sum + cnt;
			}
		}
		else dp[u][1] = sum+cnt;
	}
	//cerr<<u<<' '<<dp[u][0]<<' '<<dp[u][1]<<'\n';
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int u,v; cin>>u>>v;
		adj[u].pb(v); adj[v].pb(u);
	}
	dfs(0,-1);
	cout<<dp[0][1]<<'\n';
}


Measured memory_bytes: 16000
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll temp1 = a*c;
    ll temp2 = a*d;
    ll temp3 = b*c;
    ll temp4 = b*d;
    ll ans = max({temp1,temp2,temp3,temp4});
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>

using namespace std;

typedef complex<double> P;

int main(){

	int t;
	cin>>t;
	while(t--){
		string s,t;
		cin>>s>>t;
		int len = (int)max(s.size(),t.size());
		reverse(s.begin(),s.end());
		reverse(t.begin(),t.end());
		string ans;

		bool f = false;
		for (int i = 0; i < len; i++)
		{
			char add = 0;
			if(f){
				add++;
				f = false;
			}
			add += (i < (int)s.size()) ? s[i] - '0' : 0;
			add += (i < (int)t.size()) ? t[i] - '0' : 0;
			if(add >= 10){
				add -= 10;
				f = true;
			}
			ans.push_back(add + '0');
		}
		if(f)
			ans.push_back('1');

		reverse(ans.begin(),ans.end());

		if(ans.length() > 80){
			cout << "overflow" << endl;
		}else {
		cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int N=100005,mod=1000000007;
char s[N];
int dp[N][15],p[N];
inline int add(int &a,int b)
{
	a=a+b;
	if(a>=mod)
		a-=mod;
}
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	p[n]=1;
	for(int i=n-1;i>=1;i--)
		p[i]=p[i+1]*10%13;
	s[0]='0';
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=9;j++)
		{
			if(s[i]!='?'&&s[i]!=j+'0')
				continue;
			for(int k=0;k<13;k++)
			{
				add(dp[i][(j*p[i]+k)%13],dp[i-1][k]);
			}
		}
	}
	printf("%d\n",dp[n][5]);
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    for(int i = 1; i<=9; i++) {
        for(int j = 1; j<= 9; j++) {
            if( n == i * j) {
                puts("Yes");
                return 0;
            }
        }
    }

    puts("No");
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n;
    while(cin>>n){
        ll ans=0, tmp=0, sm=0;
        for(int i=0; i<n; ++i){
            scanf("%d",a+i);
            sm+=a[i];
        }
        ans=sm;
        for(int i=0; i<n; ++i){
            tmp+=a[i];
            ans=min(ans, abs(sm-tmp-tmp));
        }
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int[] vis = new int[2000001];
		int N = input.nextInt();
		long cnt = 0;
		for (int i = 1; i <= N; i++) {
			int x = input.nextInt();
			if (i+x<=200000) vis[i+x]++;
			if (i-x>=0) cnt+=vis[i-x];
		} 
		System.out.println(cnt);
	}
}

Measured memory_bytes: 56528