akhauriyash/Code-Regression huggingface dataset:
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.append(X)
y.append(Y)
x = max(x)
y = min(y)

if (x < y):
    print("No War")
else:
    print("War")

Measured memory_bytes: 61972
from numpy import *
N,K = map(int,input().split())
A = log(array(list(map(int,input().split()))))
B = [sum(A[:K])]

for n in range(N-K):
  B+=[B[-1]+A[n+K]-A[n]]
  
  if B[n]<B[n+1]:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 50264
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

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


Measured memory_bytes: 256
#include <stdio.h>

#define N 12

int main (
  void
  )
{
  for ( ; ; )
  {
    int aim, money[ N ];
    int i;

    scanf ( "%d", &aim );
    if ( !aim ) break ;

    for ( i = 0; i < N; ++i )
    {
      int m, n;
      scanf ( "%d%d", &m, &n );

      money[ i ] = m - n;
    }
    for ( i = 1; i < N; ++i )
    {
      money[ i ] += money[ i - 1 ];
    }

    for ( i = 0; i < N; ++i )
    {
      if ( money[ i ] >= aim )
      {
        printf ( "%d\n", i + 1 );
        goto CONTT;
      }
    }
    puts ( "NA" );

CONTT: ;
  }

  return ( 0 );
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var P = Enumerable.Repeat(0, N).Select(i => ReadInt()).ToArray();
            var Q = new int[N];
            for (int i = 0; i < N; i++) Q[P[i] - 1] = i;
            var ans = 0;
            var cnt = 0;
            var chk = -1;
            for (int i = 0; i < N; i++)
            {
                if (Q[i] > chk)
                {
                    cnt++;
                    chk = Q[i];
                }
                else
                {
                    if (cnt > ans) ans = cnt;
                    cnt = 1;
                    chk = Q[i];
                }
            }
            if (cnt > ans) ans = cnt;

            Console.WriteLine(N - ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 18524
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  ll gr[n];
  rep(i, n){
cin>>gr[i];}
  
  ll dis[n-1];
  rep(i, n-1){
    dis[i]=gr[i+1]-gr[i];}
  
  ll wg=b/a;
  ll cnt=0;
  
  rep(i, n-1){
    if(dis[i]<=wg){
      cnt+=dis[i]*a;}
    else{
      cnt+=b;}
  }
  
  cout<<cnt<<endl;
  
  
  
}

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

int main() {
    int n, d;
    long long x, y;
    cin >> n >> d;
    int count = 0;
    for(int i = 0; i < n; i++){
        cin >> x >> y;
        if(sqrt(x * x + y * y) <= d){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3608
n,m,c = map(int, input().split())
b = list(map(int, input().split()))
d = 0
for i in range(n):
    a = list(map(int, input().split()))
    e =0
    for j in range(m):
        e += a[j]*b[j]
    else:
        if e+c > 0: d+=1
print(d)

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

int n;
Graph G;
ll dist[100010];

void dfs(int v,int p,ll c){
    dist[v]=dist[p]+c;
    for(auto x:G[v]){
        int nx=x.first;
        int nc=x.second;
        if(nx==p)continue;
        dfs(nx,v,nc);
    }
}
int main(){
    cin >> n;
    G.resize(n);
    rep(i,n-1){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        G[a].push_back(make_pair(b,c));
        G[b].push_back(make_pair(a,c));
    }
    int q,k;
    cin >> q >> k;
    k--;
    rep(i,n){
        dist[i]=0;
    }
    dist[-1]=0;
    dfs(k,-1,0);
    rep(i,q){
        int x,y;
        cin >> x >> y;
        x--;y--;
        ll ans = dist[x]+dist[y];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int H,W,K;
char c[7][7];

bool IsRed[70]; // true = 選ばれてる

int vector_finder(vector<int> vec, int number) {
    for(int i = 0;i < vec.size();i++){
        if(vec[i] == number) return true;
    }

    return false;
}

int main(){
    cin >> H >> W >> K;
    for(int y = 0;y < H;y++){
        for(int x = 0;x < W;x++){
            cin >> c[x][y];
        }
    }

    int ans = 0;
    int n = H + W;
    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<n); ++bit)
    {
        /* bit で表される集合の処理を書く */


        /* きちんとできていることを確認してみる */
        // bit の表す集合を求める
        vector<int> S;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
                S.push_back(i);
            }
        }

        int counter = 0;

        for(int i = 0;i < 30;i++){
            IsRed[i] = false;
        }

        for(int j:S){
            IsRed[j] = true;
        }


        for(int y = 0;y < H;y++){
            for(int x = 0;x < W;x++){
                if(c[x][y] == '#' && IsRed[x] == false && IsRed[W + y] == false){
                    counter++;
                }
            }
        }

        if(counter == K) {
            ans++;
        }

    }

    cout << ans << endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int res = 0;
    rep (i, n / b + 1) {
        int x = n - b * i;
        rep (j, x / g + 1) {
            int y = x - j * g;
            if (y < 0) break;
            if (y % r == 0) res++;
        }
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 256
<?php
# B - Balance

fscanf(STDIN, "%d", $N);
$array = explode(' ', fgets(STDIN));

#累積和を作る
$sum_array = [];
$sum_array[] = 0;
for ( $i = 0 ; $i < $N ; $i++ ) {
    $sum_array[] += ($sum_array[$i] + $array[$i]);
}

#差の絶対値の最小値を出力
$min_array = [];
$T = $N - 1;
for ( $i = 1 ; $i <= $T ; $i++ ) {
    $min_array[] = abs(($sum_array[$N] - $sum_array[$i]) - $sum_array[$i]);
}

echo min($min_array);


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

int main() {
    int A, B;
    cin >> A >> B;
    string S;
    cin >> S;
    bool tmp1 = false;
    bool tmp2 = true;
    rep(i, A + B + 1) {
        if (i == A) if (S[i] == '-') tmp1 = true;
        if (i != A) if (!('0' <= S[i] && S[i] <= '9')) tmp2 = false;
    }
    if (tmp1 && tmp2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
const int N=5e5+7;
typedef long long ll;
const ll mod=1e9+7;
ll arr[N];
ll mark[N];
ll right_[N];
ll ans=0;
void merage_sort(ll l,ll r){
    if(l>=r) return ;
    ll mid=(l+r)/2;
    merage_sort(l,mid);
    merage_sort(mid+1,r);
    ll i=l,j=mid+1,k=l;
    while(i<=mid&&j<=r){
        if(arr[i]<=arr[j]){
            right_[k++]=arr[i++];
        }
        else {
            right_[k++]=arr[j++];
            ans+=1ll*mid-i+1;
        }
    }
    while(i<=mid)    right_[k++]=arr[i++];
    while(j<=r)   right_[k++]=arr[j++];    
    for(ll i=l;i<=r;i++)    arr[i]=right_[i];
}
int main(){
    ll n,k;
    cin>>n>>k;
    for(ll i=1;i<=n;i++){
        cin>>arr[i];
        mark[i]=arr[i];
    }
    ll ans1;
    merage_sort(1,n);
    ans1=ans;
    ll ans2=0;
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=n;j++){
    		if(arr[i]>arr[j]) ans2++;
		}
	}
	cout<<(k%mod*ans1%mod+k%mod*(k-1)/2%mod*ans2%mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 4352
#include <stdio.h>

int gcd(int x, int y){
    if(y == 0)
        return x;
    else
        return gcd(y, x%y);
}

int main(void){
    int x, y;
    scanf("%d", &x); scanf("%d", &y);
    printf("%d\n", gcd(x, y));

    return 0;
}

Measured memory_bytes: 592
// ARC101B.cpp
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAX_N = 4e5 + 200;

ll nodes[MAX_N << 1];
int n, ai[MAX_N], upper, diff[MAX_N];

int lowbit(int x) { return x & (-x); }

void update(int x, int d)
{
    for (; x <= upper; x += lowbit(x))
        nodes[x] += d;
}

ll query(int x, ll ret = 0)
{
    for (; x; x -= lowbit(x))
        ret += nodes[x];
    return ret;
}

bool check(int mid)
{
    memset(nodes, 0, sizeof(nodes));
    for (int i = 1; i <= n; i++)
        diff[i] = (ai[i] >= mid ? 1 : -1);
    for (int i = 1; i <= n; i++)
        diff[i] += diff[i - 1];
    ll pans = 0;
    for (int i = 0; i <= n; i++)
    {
        pans += query(diff[i] + MAX_N);
        update(diff[i] + MAX_N, 1);
    }
    return pans >= (1LL * n * (n + 1) / 4);
}

int main()
{
    scanf("%d", &n), upper = MAX_N << 1;
    for (int i = 1; i <= n; i++)
        scanf("%d", &ai[i]);
    int l = 0, r = *max_element(ai + 1, ai + 1 + n), res;
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        if (check(mid))
            l = mid + 1, res = mid;
        else
            r = mid - 1;
    }
    printf("%d\n", res);
    return 0;
}

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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
template <typename T> using VVV = vector<vector<vector<T>>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

void solve() {
    lint N;
    cin >> N;

    lint keta = 0;
    lint tn = N;
    while(tn) {
        tn /= 10;
        keta++;
    }

    tn = N;
    lint keta_sum = 0;
    rep(i, keta) {
        keta_sum += tn % 10;
        tn /= 10;
    }

    string ans;
    if(N % keta_sum == 0) {
        ans = "Yes";
    } else {
        ans = "No";
    }

    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define gcda(x,y) gcd(abs(x),abs(y))

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main(){
    int n;
    cin >> n;
    int ac = 0, wa = 0, tle = 0, re = 0;
    REP(i,n){
      string s;
      cin >> s;
      if(s=="AC") ac++;
      if(s=="WA") wa++;
      if(s=="TLE") tle++;
      if(s=="RE") re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n;
  cin >> n;
  ll a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[i]=a[i];
  }
  sort(b,b+n,greater<ll>());
  for(int i=0;i<n;i++){
    if(a[i]==b[0]){
      cout << b[1]<<endl;
    }else{
      cout << b[0]<<endl;
    }
  }
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int n, k;
vector<int> edge[100005];
vector<int> col;
map<pii,int> ma;
signed main() {

    cin >>n;
    vector<int> a(n), b(n);
    col.resize(n);
    
    for(int i = 0; i < n-1; i++) {
        cin >> a[i] >> b[i];
        a[i]--,b[i]--;
        edge[a[i]].bash(b[i]);
        edge[b[i]].bash(a[i]);
    }

    queue<int> que;
    vector<bool> isV(n);
    que.push(0);
    isV[0] = true;
    while(!que.empty()) {
        int  u = que.front();
        que.pop();
        int c = 1;
        chmax(k,(int)edge[u].size());
        for(auto&&v:edge[u]) {
            if(isV[v]) continue;
            if(c==col[u]) c++;
            col[v] = ma[pii(u,v)] = ma[pii(v,u)] = c++;
            isV[v] = true;
            que.push(v);
        }
    }
    cout << k << endl;
    for(int i = 0; i < n-1; i++) {
        cout << ma[pii(a[i],b[i])] << endl;
    }

    return 0;
}



Measured memory_bytes: 19712
h, w = map(int, input().split())
board = [input().split() for _ in range(h)]
a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i in range(h):
    for j in range(w):
        if board[i][j] == "snuke":
            print(a[j]+str(i+1))

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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  char A = toupper(a.at(0));
  char B = toupper(b.at(0));
  char C = toupper(c.at(0));
  cout << A << B << C << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int n,i,ans,sa1,sa2;
scanf("%d",&n);  
int w[n],sum[n];
  
  scanf("%d",&w[i]);
  sum[0]=w[0];
  
  for(i=1;i<n;++i)
  {scanf("%d",&w[i]);
  sum[i]=sum[i-1]+w[i];
  }
  
  for(i=0;sum[i]<sum[n-1]/2;++i)
  {ans=i;}
  
  sa1=sum[n-1]-sum[ans]*2;
  sa2=2*sum[ans+1]-sum[n-1];
  
  if(sa1<sa2) printf("%d",sa1);
  else printf("%d",sa2);
  
return 0;
}

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

typedef long long ll;
#define PB push_back

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int k; cin >> k;
	ll sum = 0;
	for (int i = 1; i <= k; ++i) {
		for (int j = 1; j <= k; ++j) {
			for (int l = 1; l <= k; ++l) {
				sum += gcd(gcd(i, j), l);
			}
		}
	}
	cout << sum;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<int>adj[100001];
int visited[100001];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    int n=s.size();
    int c=0;
    int i,j;
    for(int i=0;i<n;i++){
            if(s[i]!=s[n-i-1]&&i<n-i-1)c++;
    }
    cout<<c;
    
    
}

Measured memory_bytes: 2560
function main(input) {
  const arg = input.split('\n')
  const t = arg[0].split(' ')
  var h = t[0], n = t[1]
  var a = arg[1].split(' '), s = 0
  for(var i=0;i<n;i++) s += parseInt(a[i], 10)
  console.log(h<=s?'Yes':'No')
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
#include <stdio.h>
#define N 10

int main(void){
	double a, sum; int i;
	
	while(~scanf("%lf",&a)){
		sum=0, i=1;
		
		while(i<=N){
			sum+=a;
			
			if(i%2==0) a/=3;
			else a*=2;
			i++;
		}
		
		printf("%f\n",sum);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

int main(){
	long long n, a, b, ans;
	cin >> n >> a >> b;
	if(a > b || (n == 1 && a != b)){
		cout << 0 << endl;
	}else{
		ans = a + b * (n - 1) - (b + a * (n - 1) - 1);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/priority_queue.hpp>
#define For(i,a,b) for(i=(a);i<=(b);++i)
#define Forward(i,a,b) for(i=(a);i>=(b);--i)
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define Chkmin(a,b) a=a<b?a:b
#define Chkmax(a,b) a=a>b?a:b
using namespace std;
using namespace __gnu_pbds;
template<typename T>inline void read(T &x)
{
    T s=0,f=1;char k=getchar();
    while(!isdigit(k)&&(k^'-'))k=getchar();
    if(!isdigit(k)){f=-1;k=getchar();}
    while(isdigit(k)){s=s*10+(k^48);k=getchar();}
    x=s*f;
}

const int MAXN=1e5+7;

static int n,m,s,t;

static struct edge
{
	int v,w1,w2,nxt;
}p[MAXN<<1];

static int head[MAXN],e;

inline void add(int u,int v,int w1,int w2)
{p[++e]=(edge){v,w1,w2,head[u]};head[u]=e;}

static long long dis[2][MAXN],vis[MAXN];

queue<int>G;

inline void spfa(int s,int t)
{
	memset(dis,0x3f,sizeof dis);
	dis[0][s]=0;dis[1][t]=0;
	G.push(s);vis[s]=1;
	static int u;
	while(!G.empty())
	{
		u=G.front();G.pop();
		for(register int v=head[u];v;v=p[v].nxt)if(dis[0][p[v].v]>dis[0][u]+p[v].w1)
		{
			dis[0][p[v].v]=dis[0][u]+p[v].w1;
			if(!vis[p[v].v])vis[p[v].v]=true,G.push(p[v].v);
		}
		vis[u]=false;
	}
	
	G.push(t);vis[t]=1;
	while(!G.empty())
	{
		u=G.front();G.pop();
		for(register int v=head[u];v;v=p[v].nxt)if(dis[1][p[v].v]>dis[1][u]+p[v].w2)
		{
			dis[1][p[v].v]=dis[1][u]+p[v].w2;
			if(!vis[p[v].v])vis[p[v].v]=true,G.push(p[v].v);
		}
		vis[u]=false;
	}
}

const long long inf=1e15;

static long long ans[MAXN];

inline void solve()
{
	read(n);read(m);read(s);read(t);
	static int u,v,w1,w2;
	Rep(i,1,m)
	{
		read(u);read(v);read(w1);read(w2);
		add(u,v,w1,w2),add(v,u,w1,w2);
	}
	spfa(s,t);
	ans[n]=dis[0][n]+dis[1][n];
	Repe(i,n-1,1)ans[i]=min(ans[i+1],dis[0][i]+dis[1][i]);
	Rep(i,1,n)printf("%lld\n",inf-ans[i]);
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 8448
def main():
	n, ma, mb, *L = map(int, open(0).read().split())
	M = 1<<30
	dp = [[M] * 420 for _ in range(420)]
	dp[0][0] = 0
	for a, b, c in zip(*[iter(L)] * 3):
		for i in range(400, -1, -1):
			for j in range(400, -1, -1):
				t = dp[i][j] + c
				if dp[i + a][j + b] > t:
					dp[i + a][j + b] = t
	ans = M
	_ma, _mb = ma, mb
	while _ma < 410 > _mb:
		ans = min(ans, dp[_ma][_mb])
		_ma += ma
		_mb += mb
	print(ans if ans < M else -1)

if __name__=="__main__":
	main()

Measured memory_bytes: 4980
def resolve():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    cost = [float("inf")]*n
    cost[0] = 0
    for i in range(n):
        for j in range(1, min(k+1, n-i)):
            cost[i+j] = min(cost[i+j], cost[i] + abs(h[i+j]-h[i]))
    print(cost[n-1])
resolve()

Measured memory_bytes: 55008
# サイコロを振る回数
count = int(input())
# ゾロ目の回数
zorome = 0

for i in range(0, count):
  dice1, dice2 = input().split()

  # ゾロ目が3回で連続たらループ抜ける
  if zorome == 3:
    break

  if dice1 == dice2:
    zorome += 1
  else:
    zorome = 0
  
if zorome == 3:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 9064
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

[[maybe_unused]] constexpr ll LL_MAX = numeric_limits<ll>::max();
[[maybe_unused]] constexpr ll LL_MIN = numeric_limits<ll>::min();
[[maybe_unused]] constexpr ull ULL_MAX = numeric_limits<ull>::max();

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

template <typename T>
void chmin(T& x, T y) {
    x = min(x, y);
}

template <typename T>
void chmax(T& x, T y) {
    x = max(x, y);
}

ll csum(ll x, ll y) {
    if (x > 0 && y > 0 && x > LL_MAX - y) {
        return LL_MAX;
    }
    if (x < 0 && y < 0 && x < LL_MIN - y) {
        return LL_MIN;
    }
    return x + y;
}

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

int main() {
    ll N;
    cin >> N;
    vector<ll> us(N-1);
    vector<ll> vs(N-1);
    vector<ll> right_mins(N, LL_MAX);
    vector<ll> left_maxs(N, LL_MIN);
    rep(i,0,N-1) {
        cin >> us[i] >> vs[i];
        us[i]--;
        vs[i]--;
        if (us[i] > vs[i]) {
            swap(us[i], vs[i]);
        }
        chmin(right_mins[us[i]], vs[i]);
        chmax(left_maxs[vs[i]], us[i]);
    }
    auto count_contain = [N](ll left, ll right) {
        return (left+1)*(N-right);
    };
    ll ans = 0;
    rep(i,0,N) {
        ans += count_contain(i, i);
    }
    rep(i,0,N-1) {
        ans -= count_contain(us[i], vs[i]);
    }
//    rep(i,0,N) {
//        ll connected = 0;
//        if (left_maxs[i] != LL_MIN && right_mins[i] == LL_MAX) {
//            connected = count_contain(left_maxs[i], i);
//        } else if (left_maxs[i] == LL_MIN && right_mins[i] != LL_MAX) {
//            connected = count_contain(i, right_mins[i]);
//        } else {
//            connected += count_contain(i, right_mins[i]);
//            connected += count_contain(left_maxs[i], i);
//            connected -= count_contain(left_maxs[i], right_mins[i]);
//        }
//        ll isolated = N * (N+1) / 2 - connected;
//        ans -= isolated;
//    }
    cout << ans << endl;
}


Measured memory_bytes: 9244
#include<cstdio>
#include<cstring>
#define maxn 25
#define maxt 2097160
#define mod 1000000007
int n,m,k,dp[2][maxn][maxt],nxt[maxt][maxn],bz[maxn][maxn],ans;
int main()
{
	scanf("%d%d%d",&n,&m,&k); n--;
	for(int i=0;i<(1<<n);i++)
		for(int j=n-1,t=-1;j>=0;j--)
		{
			if(i&(1<<j)) t=j;
			nxt[i][j]=t;
		}
	for(int i=1;i<=m;i++)
		for(int j=0;j<n;j++) bz[i][j]=-1;
	for(int i=1;i<=k;i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		bz[x][y-1]=z;
	}
	int now=1; dp[0][n][0]=1;
	for(int i=1;i<=m;i++,now^=1)
	{
		for(int s=0;s<(1<<n);s++) dp[now][0][s]=dp[now^1][n][s];
		//memset(dp[now^1],0,sizeof(dp[now^1]));
		for(int j=0;j<=n;j++)
			for(int s=0;s<(1<<n);s++) dp[now^1][j][s]=0;
		for(int j=0;j<n;j++)
			for(int s=0;s<(1<<n);s++)
				if(dp[now][j][s])
					for(int k=0;k<2;k++)
					{
						if(bz[i][j]!=-1&&bz[i][j]!=k) continue;
						int t=(s>>j)&1;
						if(!k&&t) continue;
						if(k==t) dp[now][j+1][s]=(dp[now][j+1][s]+dp[now][j][s])%mod;
						else
						{
							int r=nxt[s][j];
							if(r==-1) dp[now][j+1][s+(1<<j)]=(dp[now][j+1][s+(1<<j)]+dp[now][j][s])%mod;
							else dp[now][j+1][s+(1<<j)-(1<<r)]=(dp[now][j+1][s+(1<<j)-(1<<r)]+dp[now][j][s])%mod;
						}
					}
	}
	for(int s=0;s<(1<<n);s++) ans=(ans+dp[now^1][n][s])%mod;
	printf("%d\n",(ans+mod)%mod);
}


Measured memory_bytes: 217344
A, B, N = list(map(int, input().split()))

c = 0
ans = 0

if N < 1000001:
  for i in range(1,N+1):
    c = int(A*i/B) - A*int(i/B)
    if ans < c:
      ans = c

elif N < B:
  ans = int(A*N/B) - A*int(N/B)
      
else:
  count = B-1
  for i in range(10000):
    c = int(A*count/B) - A*int(count/B)
    if ans < c:
      ans = c
    count += B
    
print(int(ans))

Measured memory_bytes: 9212
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vector<double> a(n);
    double sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    double ave = sum / n;
    
    vector<pair<double, ll>> p(n);
    rep(i, n) {
        p[i] = make_pair(abs(ave - a[i]), i);
    }
    sort(all(p));

    out(p[0].second);
    re0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 2000000

int H,a[MAX+1];

void maxheap(int i){
  int l,r,largest,t;
  l=2*i;
  r=2*i+1;

  if(l<=H && a[l]>a[i])largest=l;
  else largest=i;
  if(r<=H && a[r]>a[largest])largest=r;

  if(largest!=i){
    t=a[i];
    a[i]=a[largest];
    a[largest]=t;
    maxheap(largest);
  }
}

int main(){
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++)scanf("%d",&a[i]);
  for(i=H/2;i>=1;i--)maxheap(i);
  for(i=1;i<=H;i++)printf(" %d",a[i]);
  printf("\n");
  return 0;
}


Measured memory_bytes: 3736
#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
  stack<int> StkIdx;
  stack<pair<int, int> > StkSur;

  char field[20000];
  scanf("%s", field);

  int sum = 0;
  for(int i = 0; field[i] != '\0'; i++) {
    if(field[i] == '\\') {
      StkIdx.push(i);
    } else if(field[i] == '/' && StkIdx.size() > 0) {
      int j = StkIdx.top();
      StkIdx.pop();
      sum += i - j;
      int a = i - j;
      while(StkSur.size() > 0 && StkSur.top().first > j) {
        a += StkSur.top().second;
        StkSur.pop();
      }
      StkSur.push(make_pair(j, a));
    }
  }

  vector<int> ans;
  while(StkSur.size() > 0) {
    ans.push_back(StkSur.top().second);
    StkSur.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for(unsigned i = 0; i < ans.size(); i++) {
    cout << " ";
    cout << ans[i];
  }
  cout << endl;

  return 0;
}

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

int main() {

  int a, b;
  cin >> a >> b;
  
  if ((a == 1 && b == 2) || (a == 2 && b == 1)) {
    cout << 3 << endl;
  } else if ((a == 1 && b == 3) || (a == 3 && b == 1)) {
    cout << 2 << endl;
  } else if ((a == 3 && b == 2) || (a == 2 && b == 3)) {
    cout << 1 << endl;
  }
   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
int N;
int main(){
	cin>>N;
	map<int,int> mp;
	REP(i,N){
		int a;
		cin>>a;
		mp[a]++;
	}
	int ma1,ma2;
	ma1=ma2=0;
	for(auto ite:mp){
		if (ite.second>=4){
			ma1=ma2=ite.first;
		}else if (ite.second>=2){
			ma2=ma1;
			ma1=ite.first;
		}
	}
	cout<<(ll)ma1*ma2<<endl;
	return 0;
}

Measured memory_bytes: 4992
//
// Created by yijiezhu on 12/20/16.
//

#include <iostream>
#include <queue>
#include <cstring>

using namespace std;

const int MAX_N = 1001;
char matrix[MAX_N][MAX_N];
bool visited[MAX_N][MAX_N];
int H, W, N, si, sj;
int delta[] = {0, 1, 0, -1, 0};

void solve() {
    int cnt{0};
    for (int ni = 1; ni <= N; ni++) {
        queue<pair<pair<int, int>, int> > que;
        que.push(make_pair(make_pair(si, sj), 0));
        memset(visited, false, sizeof(visited));
        visited[si][sj] = true;
        while(!que.empty()) {
            auto p = que.front();
            que.pop();
            int x = p.first.first, y = p.first.second;
            if (matrix[x][y] == '0' + ni) {
                si = x; sj = y;
                cnt += p.second;
                break;
            }
            for (int q = 0; q < 4; q++) {
                int n_i = x + delta[q], n_j = y + delta[q+1];
                if (n_i < 0 || n_i >= H || n_j < 0 || n_j >= W) continue;
                if (matrix[n_i][n_j] == 'X' || visited[n_i][n_j]) continue;
                que.push(make_pair(make_pair(n_i, n_j), p.second + 1));
                visited[n_i][n_j] = true;
            }
        }
    }
    cout << cnt << endl;
}

int main() {
    cin >> H >> W >> N;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> matrix[i][j];
            if (matrix[i][j] == 'S') {
                si = i; sj = j;
            }
        }
    }
    solve();
}

Measured memory_bytes: 5040
require "date"

YEAR = 2004
WDAY = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

while true
  m, d = gets.split.map(&:to_i)
  
  break if m == 0 && d == 0
  
  puts WDAY[Date.new(YEAR, m, d).wday]
end

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

int main(){
  long n;
  cin >> n;
  long ans = 1;
  long tmp = n;
  for(long i=2;i<=sqrt(n);i++){
    tmp = n;
    while(tmp%i==0)tmp /= i;
    if(tmp%i==1){
      ans++;
    }
  }
  for(long j=2;j<=sqrt(n);j++){
    if((n-1)%j==0 && (n-1)/j>sqrt(n))ans++;
  }
  cout << ans+(n>2) << endl;
  return 0;
}

Measured memory_bytes: 3564
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   N : Integer;
begin
   Get (N);
   if N < 1000 then
      Put_Line ("ABC");
   else
      Put_Line ("ABD");
   end if;
end Solve;

Measured memory_bytes: 3664
#include <stdio.h>
int main(void) {
	while(1){
		int n;
		scanf("%d",&n);
		if(n==0) break;
		int i,pm[n],pe[n],pj[n];
		for(i=0;i<n;i++){
			scanf("%d %d %d",&pm[i],&pe[i],&pj[i]);
		}
		int pme[n],pmej[n];
		for(i=0;i<n;i++){
			pme[i]=(pm[i]+pe[i])/2;
			pmej[i]=(pm[i]+pe[i]+pj[i])/3;
			if(pm[i]==100||pe[i]==100||pj[i]==100||pme[i]>=90||pmej[i]>=80){
				puts("A");
			}
			else if(pmej[i]>=70||(pmej[i]>=50&&(pm[i]>=80||pe[i]>=80))){
				puts("B");
			}
			else{
				puts("C");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 1980
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - ModSum
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

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

  printf("%lld\n", (ll)n * (n - 1) / 2);
  return 0;
}


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

using namespace std;

int n;
string s;

int main()
{
    cin >> s;
    n = s.size();
    long long ans = 0;
    for (int bit = 0; bit < 1 << (n - 1); ++bit) {
        int j = 0;
        while(j < n) {
            int prev = j;
            while(!((bit >> j) & 1) && j < n) j++;
            ans += stol(s.substr(prev, j - prev + 1));
            j++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 760
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int x;
    cin >> x;
    int t = 1;
    int sum = 0;
    while (true)
    {
        sum += t;
        if (sum >= x)
        {
            cout << t << endl;
            break;
        }
        t++;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string s0;
        if(!(getline(cin, s0)))
            return 0;
        int n = s0.size();
        string s;
        for(int i=0; i<n; ++i){
            if('a' <= s0[i] && s0[i] <= 'z')
                s.push_back(s0[i] - 'a' + 'A');
            if('A' <= s0[i] && s0[i] <= 'Z')
                s.push_back(s0[i]);
        }
        n = s.size();

        set<string> palindrome, notPalindrome;
        for(int i=0; i<2*n; ++i){
            int j = i/2;
            int k = i/2;
            if(i % 2 == 1)
                -- k;
            while(j-1 >= 0 && k+1 < n && s[j-1] == s[k+1]){
                -- j;
                ++ k;
            }
            if(k - j < 2)
                continue;
            string s1 = s.substr(j, k-j+1);
            if(notPalindrome.find(s1) != notPalindrome.end())
                continue;
            palindrome.insert(s1);
            while(k - j >= 4){
                ++ j;
                -- k;
                s1 = s.substr(j, k-j+1);
                set<string>::iterator it = palindrome.find(s1);
                if(it != palindrome.end())
                    palindrome.erase(it);
                notPalindrome.insert(s1);
            }
        }

        set<string>::iterator it;
        bool first = true;
        for(it=palindrome.begin(); it!=palindrome.end(); ++it){
            if(!first)
                cout << ' '; 
            else
                first = false;
            cout << (*it);
        }
        cout << endl;
    }
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int N;
	string S;

	cin >> N;
	cin >> S;
	int ans = 0;
	int left = 0, right = N;
	fx(30) {
		int mid = (left + right) / 2;
		map<string, int> K;
		bool flag = false;
		for (int y = 0; y + mid <= N;y++) {
			if (K[S.substr(y, mid)]==0) {
				K[S.substr(y, mid)] = y + 1;
			}
			else {
				if (K[S.substr(y, mid)] + mid -1<= y) {
					flag = true;
					break;
				}
			}

		}
		if (flag) {
			left = mid;
		}
		else {
			right = mid;
		}
	}
	ce((left + right) / 2)
    return 0;
}



Measured memory_bytes: 6672
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

ll calc(){
    int n;
    cin >> n;
    VVI a(n), b(n);
    ll ans = 0;
    REP(i,n){
        int k = in() - 1, l = in(), r = in();
        if (r > l){
            if (k < n - 1) a[k + 1].push_back(r - l);
        }else if (r < l){
            b[k].push_back(l - r);
        }
        ans += min(l, r);
    }
    priority_queue<ll> quea, queb;
    REP(i,n){
        for (ll x : a[i]) quea.push(x);
        if (!quea.empty()){
            ans += quea.top();
            quea.pop();
        }
    }
    FORR(i,n-1,0){
        for (ll x : b[i]) queb.push(x);
        if (!queb.empty()){
            ans += queb.top();
            queb.pop();
        }
    }
    return ans;
}

int main(void){
    int t;
    cin >> t;
    while (t--){
        printf("%lld\n", calc());
    }
    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_H 1000
#define MAX_W 1000
#define MOD 1'000'000'007
i64 H, W;
char maze[MAX_H][MAX_W];
i64 dp[MAX_H][MAX_W];

int main() {
    cin >> H >> W;
    REP(y, H) REP(x, W) {
        cin >> maze[y][x];
    }

    dp[0][0] = 1;
    REP(y, H) REP(x, W) {
        if (x == 0 && y == 0) continue;

        if (maze[y][x] == '#') {
            dp[y][x] = 0;
            continue;
        }
        if (y == 0) {
            dp[y][x] = dp[y][x - 1];
            continue;
        }
        if (x == 0) {
            dp[y][x] = dp[y - 1][x];
            continue;
        }
        dp[y][x] = dp[y - 1][x] + dp[y][x - 1];
        dp[y][x] %= MOD;
    }

    cout << dp[H - 1][W - 1] << endl;

    return 0;
}

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

#define LL 					long long
#define ULL 				unsigned long long
#define pii 				pair<int,int>
#define fi 					first
#define se 					second
#define vi 					vector<int>
#define psb 				push_back
#define ppb 				pop_back
#define all(x)			 	(x).begin(),(x).end()
#define sz(x)				(int)(x).size()
#define endln 				printf("\n")
#define gc					getchar_unlocked
#define setmin(x)			memset((x), -1, sizeof((x)))
#define setnul(x)			memset((x), 0, sizeof((x)))
#ifndef getchar_unlocked
#define getchar_unlocked 	getchar
#endif
const int inf = 1e9 + 5;
const LL infll = 1e18+5;
const int mod = 1e9 + 7;

template <typename T>
void gi(T &ret) {
	ret = 0; char inp=gc(); int kl=1;
	while (inp<'0' || inp>'9') {if (inp=='-') kl=-1; inp=gc();}
	while ('0'<=inp && inp<='9') ret=(ret<<3)+(ret<<1)+(inp-'0'), inp=gc();
	if (kl<1) ret=-ret;
}

const int MAXN = 2e3+5;
int n, bts;
int cnt[2][MAXN+MAXN], val[2][MAXN];
int add[MAXN][MAXN][2];

char inp[5];

int bit[MAXN+MAXN];
void update (int x, int v) {
	for (int i=x; i<=bts; i+=i&(-i))
		bit[i] += v;
}
int get (int x) {
	int ret = 0;
	for (int i=x; i>0; i-=i&(-i))
		ret += bit[i];
	return ret;
}

void precomp() {
	int va = 0, tpa, vb, tpb;
	setnul(bit);
	for (int i=1; i<=2*n; i++) update(i,1);
	for (int i=0; i<=n; i++) {
		if (i) update(val[0][i], -1);
		
		for (int j=0; j<=n; j++) {
			if (j) update(val[1][j], -1);
			if (i<n) add[i][j][0] = get (val[0][i+1]-1);
			if (j<n) add[i][j][1] = get (val[1][j+1]-1);
		}

		for (int j=1; j<=n; j++) update(val[1][j], 1);
	}
}

int dp[MAXN][MAXN];

int getdp (int a, int b) {
	if (a>n && b>n) return 0;
	int &ret = dp[a][b];
	if (ret != -1) return ret;
	ret = inf;
	if (a<=n) ret = min(ret, add[a-1][b-1][0]+getdp(a+1,b));
	if (b<=n) ret = min(ret, add[a-1][b-1][1]+getdp(a,b+1));
	// printf ("dp %d %d = %d\n", a, b, ret);
	return ret;
}

int main() {
	gi(n);
	bts = n+n;
	for (int i=1; i<=bts; i++) {
		scanf("%s", inp);
		int x; gi(x);
		if (inp[0]=='W') {
			val[0][x] = i;
			// printf ("0 %d\n", i);
		}
		else {
			val[1][x] = i;
			// printf ("1 %d\n", i);
		}
	}
	precomp();
	setmin(dp);
	printf ("%d\n", getdp(1,1));
	return 0;
}

Measured memory_bytes: 47616
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int N, M; cin >> N >> M;
    vector<vector<ll>> dist(N,vector<ll>(N,INF));
    rep(i,N) dist[i][i] = 0;

    vector<ll> a(M), b(M), c(M);
    rep(i,M){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        dist[a[i]][b[i]] = c[i];
        dist[b[i]][a[i]] = c[i];
    }

    rep(k,N){
        rep(i,N){
            rep(j,N){
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }

    int ans = 0;
    rep(i,M){
        if (c[i] > dist[a[i]][b[i]]) ans++;
    }
    cout << ans << endl;
}

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

#define int long long

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

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

    sort(a, a+n, greater<int>());

    int x = -1;
    int y = -1;
    int i;
    for(i = 0;i < n-1;i++){
        if(a[i] == a[i+1]){
            x = a[i];
            break;
        }
    }

    i+=2;
    for(;i < n-1;i++){
        if(a[i] == a[i+1]){
            y = a[i];
            break;
        }
    }

    if(y == -1){
        cout << 0 << endl;
    }else{
        cout << x*y << endl;
    }

    return 0;
}




Measured memory_bytes: 1024
#include <iostream>

using namespace std;
using ll = long long;

ll mod = 1000000007;

ll modinv(ll a) {
  ll b = mod - 2;
  ll res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}

ll modmul(ll a, ll b) {
  return a * b % mod;
}

ll modadd(ll a, ll b) {
  return (a + b) % mod;
}

ll modsub(ll a, ll b) {
  ll res = (a - b) % mod;
  return (res < 0) ? res + mod : res;
}

ll hoge(ll x) {
  ll res = modmul(modmul(modinv(2), x), x + 1) - x;
  return (res < 0) ? res + mod : res;
}

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for (int i = k; i <= n+1; ++i)
    ans = modadd(modsub(modsub(modadd(ans, hoge(n+1)), hoge(n-i+1)), hoge(i)), 1);
  cout << ans << endl;
}

Measured memory_bytes: 3588
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
//#include <vector>
//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int N;
    cin >> N ;
    int flag = 0;
    for( int ni = 0 ; ni <= N/4 ; ni++ ){
        if((N-4*ni) % 7 == 0) flag = 1;
    }
    if(flag==1) cout << ans_Yes;
    else cout << ans_No;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <iomanip>
#include <deque>
#include <list>
#include <cassert>
#include <complex>
#include <bitset>
#include <deque>


using namespace std;
typedef long long ll;
#define int ll
typedef long double ld;
typedef vector<int> vi;
typedef vector<ld> vld;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
#define mmin(a, b) a = min(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SZ(a) ((int)(a).size())
#define watch(x) cout << (#x) << " = " << (x) << endl;


const int N = 1 << 17, oo = 1e9 + 10, A = 201, B = 100;
const ll M = 998244353, x = 137;





bool check(int v)
{
	int l = 0, r = v + 10;
	while (r - l > 1)
	{
		int m = (l + r) >> 1;
		if (m * (m - 1) / 2 >= v)
			r = m;
		else
			l = m;
	}

	return r * (r - 1) / 2 == v;
}



vvi blocks;


void add(int ind, int v)
{
	blocks[ind].push_back(v);
}


signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n;
	cin >> n;

	if (!check(n))
	{
		cout << "No\n";
		return 0;
	}

	cout << "Yes\n";

	int K = 1;
	for (int i = 1; i <= n; ++i)
		if (check(i))
			K++;

	cout << K << '\n';
	blocks.resize(K + 1);
	int l = 1, r = 2;

	for (int i = 1; i <= n; ++i)
	{
		add(l, i);
		add(r++, i);
		
		if (r == K + 1)
		{
			l++;
			r = l + 1;
		}
	}

	for (int i = 1; i <= K; ++i)
	{
		cout << SZ(blocks[i]) << ' ';
		for (int v : blocks[i])
			cout << v << ' ';

		cout << '\n';
	}
}

Measured memory_bytes: 3200